iOS device computational/memory limit - ios

I'm working on a game for iOS, and to start a new game the following steps are followed:
The user choose the number of pieces
Each piece is created through a loop
The game starts
On the simulator I can choose as many pieces as I want, and start as many games as I want, and the app is working fine.
But on a real device (my new iPad 3), the app crashes if I choose more than 400 pieces, and also if I start (say) 3 games with 150 pieces each. I've checked with breakpoints, it crashes in different lines: sometimes creating a piece, sometimes even after the game started. Unfortunately the console is not telling me anything.
I checked the app with instruments: there are not leaks at all, and the total allocation size is at most 4 MB. And I'm logging in didReceiveMemoryWarning in my AppDelegate, but it looks like it is never called.
My question is: how should I behave to debug this? How can I understand what the computational/memory limits of a iOS device are?

If using too much memory is causing you this problem then try a NSLog in didReciveMemoryWarning. As for the memory limit I already saw a few posts here.
How much memory does iOS allow apps to use?
or
Max application memory Limit in iPad? or
iOS memory allocation - how much memory can be used in an application?
And I think I can find a few more :)

Related

Why does my Unity ios app's Documents and Data keep increasing?

I created my first app back in July. It came out to be 55mb. I have recently noticed that the Documents and Data section for my app is 150mb, nearly 3 times the app size. Doing more tests I have realized that each time I play the game it increases by 1mb. It is now at 170mb.
I am using Unity 5.6.1p4 and Google Admob.
My app does not download any update files to run the game so that isn't the issue.
I have a couple of guesses but none seem very likely:
1) My game is only about half as optimized as it should be. I still use a lot of instantiate and destroy. An other post said that the memory issue is due to Apple's inability to garbage collect. That is a possibility but I cannot understand why the data from instantiate/destroy would be cached. I also find it hard to believe no one else has had that issue.
2) When the game first starts, it automatically loads a banner ad and a video ad so that there is no delay when the user first requests a reward video. Some people have said that Google Admob caches ads so there is less data usage. That seems like it would cause some increase in file size but 170mb is too much data to be cached. Again I find it hard to believe no one would have complained to Google about this before.
Any help would be greatly appreciated. I cannot figure out what would be causing it. If you are interested in seeing the problem first hand, the App Store link is https://appsto.re/us/nco9gb.i
Ok, here is my findings: This is either an issue for older phones, or iOS 10.x.
However, I do not know which. I am able to test iOS 10 on older phones (5, 5s and ipad 1). I am not able to find any newer device still running iOS 10. This memory glitch does not seem to happen on iOS 11. I was able to test it on 3x iphone 6s, 2x iphone 7 all running iOS 11.It is not as clear as I would like it to be but iOS 11 does not appear to have the memory issue. As much as I would like to find the cause and fix it, I think the majority of people should be safe because they update.

iOS app terminated due to memory pressure

I am trying to use image files with my app. These image files are compressed in a .zip-file which is opened from the user from the Mail App or Safari. The .zip-file (which contains the image files) is then unzipped by "SSZipArchive". This works without any problem for smaller files (e.g. 5 images, 10KB). But for bigger files (1900 images, 20MB) the app crashes and it is hard to figure out why because it only crashes when the app is not debugging and not watched by Instruments. A few times I got a crash while using the debugger but only when I opened the .zip-Archive from the Mail App. I then got the message "App terminated due to memory pressure".
Please help!
You're probably testing on the Simulator. That's never reliable, because your computer has lots of memory! Test on the device to find out under real-life conditions whether your app uses too much memory. If it does, you'll get a warning and then (if you don't do something about the problem) a deliberate termination.
The root of your problem is that you simply cannot allocate that much memory under iOS or your app/device will crash. A good rule of thumb is that you app might take 10 to 20 megs of memory while running normally, but if it jumps up to 40-80 at any point then you will be in danger of a crash. You should read up on how much memory images use when decompressed under iOS mem blog post and rework your code to make sure things stay in the 10 to 20 meg of memory usage range.

Photo Editing extension needs lots of memory and got crashed. How to avoid it?

We've developed a Photo Editing extension to edit user's photos. But the photos which user take have large high-resolution. When editing them in extension, it will cost about 100-200MB memory and extension get crashed. But we can't reduce user photo's resolution, how to apply more memory in Photo Editing extension?
I have the same problem. I'm writing an extension to complement my photo editing app. My filter pipeline is relatively complex; it uses a maximum of 6 image-sized textures at a time. However, in the main app I can even process the full camera image size of 8 MP (iPhone 5s) without running into memory issues.
In the extension, I use the display-sized image given by the framework for displaying the preview of the filter to the user, which works perfectly fine. But when I try to apply my filter to the original image as soon as the user taps Done, the extension crashes with the error message Terminated due to Memory Error (in Xcode). I even refactored my shaders and texture management code to only use half (!) of the previous amount of memory, but the extension keeps crashing.
I know Apples guide explicitly mentions lower memory limits:
Memory limits for running app extensions are significantly lower than the memory limits imposed on a foreground app. On both platforms, the system may aggressively terminate extensions because users want to return to their main goal in the host app. Some extensions may have lower memory limits than others: For example, widgets must be especially efficient because users are likely to have several widgets open at the same time. [...]
Keep in mind that the GPU is a shared resource in the system, and so app extensions don’t get top priority. For example, a Today widget that runs a graphics-intensive game may give users a bad experience on both platforms and is likely to be terminated because of memory pressures.
But I don't see how complex photo editing apps are supposed to work with that. The current memory constraints are clearly too high. The only option I see right now is to reduce the image size when saving results and prompt the user about it and tell him/her to use the main app for hi-res export ... which totally misses the point of the extension. I hope Apple will raise the limits before the final release of iOS 8.
UPDATE
I just updated to the iOS 8 GM release and the GM release of Xcode 6. Now everything works perfectly fine! I am able to process 8 MP images without any memory warning now.

What is the maximum allowed run time memory size of an iPad app? [duplicate]

This question already has an answer here:
Max application memory Limit in iPad?
(1 answer)
Closed 9 years ago.
I am developing an iPad app ( hybrid), which has native UINavigationbar and UIWebview ,thats all. I load webview with external url. It works fine for some time . But after that it is getting crashed with log in console "Received memory warning." twice. I checked the "Instruments" , it has very very less leaks discovered (around 100 bytes) and objective-codes are not all executed at that time
It clearly shows that app size increased the threshold.But is there any way to increase the size of the app , so that it will not throw memory warning error. How to handle this issue?
Any help please?
The way you have to respond to memory warnings changed in iOS 5/6. Before that you would get like three memory warnings and would be killed if you didn't do anything. Now the OS sends memory warnings more as a last resort - if you receive one, you really have to drop your footprint now. This is only indirectly linked with memory leaks.
As the docs detail, you have to respond to those notifications - and it is good to not allocate a lot of memory in a short time.
Since iOS 7 keeps even more of the suspended apps around (e.g. for the new background modes) you might get memory warnings more often.
It's important to note, that you cannot control the amount of memory your app will be reserved by the system.

iPad1 memory mystery with my texture-intensive game app

Sorry for the vague title, but not quite sure how to summarize this one.
The facts are:
I have a game that's been approved by Apple and is on the App Store.
It is a universal app. It uses textures designed for 320x480 on small screens, and uses larger textures (roughly four times as large) on retina and iPad screens.
While developing it, I would sometimes see low-memory warnings in the console log, but after reading about these it seemed like they were often somewhat spurious/unimportant, and in any event I was not having crashes, and my testers on a variety of devices (iPod Touch 2nd gen, iPod Touch 4th gen, iPhone3, iPhone4, iPad1, iPad2) were not seeing crashes.
When I started distributing the app to a wider set of beta testers through TestFlightApp, I got reports of some people seeing crashes as the app was loading, or very early after the user had chosen a level from the main menu and the app was loading the level textures. We discovered that if these users just restarted their devices, they didn't have problems any more. Since this was the first time we had seen problems like this, we attributed it to something TestFlightApp was doing, some funny state it was leaving the device in after the install (we talked to TestFlightApp about this and they had never heard of such a thing).
As stated, Apple approved the app and it's on the App Store. Soon after it went live, we got reports from some iPad1 users that it was crashing for them on app load, or soon thereafter, same kind of thing as we saw with certain TestFlightApp users. And again similar to the TestFlightApp users, these customers reported that restarting would often fix the problem. But it wasn't as nice because the problem tended to appear again. One of these users sent me several LowMemory...log files that she got off her PC after synching her iPad. There were about 10 such files, and none of them listed my program in the Processes list. Instead it showed other programs marked as either (active) or (jettisoned), and the "Largest Process" could be anything from MobileSafari to Kobo, but again my own app was never listed. So, I didn't understand that, but the bottom line seems to be that, for this user at least, something is pushing the memory over some limit where my app won't run well.
I have since gone back and talked to one of the TestFlightApp beta testers, and it turns out that he does indeed sometimes get the app crash again, so it wasn't just some residue from TestFlightApp. However, for him the crash is much less frequent than it is for this customer.
Other iPad1 testers of the game have never had any trouble. They report that they play the game for hours each day, use their iPad with several other apps in between, and rarely power it down. Similarly, I never had a crash with my iPod Touch 4th gen, which is similar to the iPad1 in the at it has a hi-res screen but only 256k RAM.
So, it's very mysterious to me what could be so different about these particular users' iPads. It's mysterious that the game works after the device is restarted, but then after some apps have been run the game (sometimes) has trouble loading. My understanding was that if my game demands memory, the OS will auto-close whatever other apps are running, as necessary, to effectively bring the amount of memory back up to the amount that's available on a freshly restarted device. My only conclusion is that after running some apps the device is left in a state where less memory is available because the OS cannot reclaim certain memory blocks or shut down certain apps.
Unfortunately I don't have one of these "misbehaving" devices to develop with. All I can think to do is try to reduce the memory needs of my app by a certain amount, and send it to one of these users who is having trouble and see if it fixes things. That seems like a potentially inefficient approach, however.
Anybody have a better idea?
Sounds like the memory spike during texture loading is what's causing the app to be terminated on some devices. It may well use less memory after everything's loaded than it does right near the end of initial loading. This could be explained by things being pushed to virtual memory, whereas direct texture loading could be bombarding the RAM with way too many allocations. My suggestions would be to:
Be more aggressive with destroying temporary data structures during loading (release a temporary structure the instant all of its useful values have been read/extracted by other things)
For autoreleased objects, keep an NSAutoreleasePool around at all times; you may even want to drain and realloc a pool several times over the course of one method if you use an exceedingly high number of autoreleased objects.
This may sound silly.. intentionally slow down your loading process. If you get rid of parallelized loads (loading multiple objects at once) or possibly insert a manual time delay in your loading thread/methods, this may give the OS more time to push things to virtual memory and thus Watchdog will not detect the app as being a RAM hog.
EDIT: One possible tactic to implement slower loading: if/when you receive a low memory warning, pause or slow loading down for a few seconds to give other apps time to lower their memory usage, then continue loading at normal speed.
Even if I'm wrong (if LowMemory...log files show Virtual+Physical usage and thus your app isn't even doing that much), I would suggest then integrating bug reporting such as QuincyKit so that you get emailed a backtrace and crash description when this bug IS encountered in the wild.

Resources