Maximum (practical) Memory Use on iPod Touch 4G, iOS 5 - ios

We have a memory-intensive 3D app which is primarily targeted at iPad 2 and iPhone 4S, but it works on iPod Touch 4G and iPhone 3GS as well. We have found that the smaller memory footprint on the iPod Touch 4G, combined with the retina display, makes this platform more susceptible to out-of-memory errors. iOS5 also seems to have lowered the available memory somewhat.
It's relatively easy for us to lower the resolution of 3D models, based on the platform we're using, but we have to set that resolution before loading, and thus we cannot effectively lower it dynamically based on memory pressure warnings from the O/S.
We've tuned the memory usage based on trial and error, but we've found that devices that haven't been rebooted in a long time (e.g., months) have a lot less useable memory than devices which have been rebooted recently. (Even if you kill off all the running apps.)
I'm wondering what other iOS app developers use as their practical memory limit for iPod Touch 4G apps?

While keeping all the caveats that everyone is offering in mind, my personal general rule of thumb has been that in sensible weather you can expect to have around the following:
512MB device -> 200MB usable (iPhone 4-4S, iPad 2)
256MB device -> 100MB usable (iPhone 3GS, iPad, iPod Touch 3G-4G)
128MB device -> 50MB usable (iPhone 3G, iPod Touch 1G-2G)
And if you want to rigorously withstand insensible weather without otherwise making a point of being flexibly responsive with memory usage, you can halve those numbers, or even third them. But it will be fairly difficult to guarantee sterling reliability if you can't throw anything overboard when conditions become dire. It's more like a sliding scale of how much performance you're willing to throw away for how much reliability at that point.
In environment predictability terms, iOS is a lot more like the PC than a dedicated machine, for better and worse, with the added bonus of a drill sergeant for an OS.

Recently I found this awesome tool to find what is the maximum memory capacity of any iOS device. We can also find at which memory level we received the Low Memory warning.
here is the link: https://github.com/Split82/iOSMemoryBudgetTest

It's hard to give an actual number because of all the external allocations the OS does on your behalf in UIKit and OpenGL. I try to keep my own allocations to around 30MB, with 50MB sort of my top end. I've pushed it as high as 90MB, but I got jettisoned a lot at that level so it's probably a bad idea unless the task using all that memory is very brief.
If you need to hack around your current problem you could just detect the problematic devices up front and turn down your graphics engine's resolution at startup. You can get exact device info or you could check for display scaling (retina) combined with number of processor cores and amount of RAM to determine what quality level to use.
I've had great success reducing my memory usage by using mapped files in place of loading data into RAM and you may want to give that a try if you have any large data allocations.
Also watch out for views/controls leaking from UIKit as they consume a lot of memory and can lead to being jettisoned at seemingly random times. I had some code which leaked child views from several view controllers. Eventually those leaks would chew up my app, though my app's memory usage didn't reflect the problem directly.

Related

Ideal memory usage amounts for iOS apps

What ranges could be considered Low, Medium, and High in memory usage?
As my app becomes more complex, I notice this number getting higher. I've been trying to use this number as an indicator to how efficiently I'm coding but I've realized I have no bar to compare it with.
How to understand Memory Usage says 1024 Mb to an iPhone/iPad, but obviously all of this memory can't go to the app.
You could get(a pretty nice) overview from this SO question. It won't show you low-medium values, but if you know the limit you can adjust below limit.
If you are near the limits in some view - override didReceiveMemoryWarning and dispose resources accordingly.
My advise is to test always on device, as simulator need a lot memory just because of it's architecture and it's not relative to real devices.

Slow performance on low memory - Swift

Been trying to find this bug for days now with no solution. Developing a ios game uising swift and only UIKit. My app displays a lot of small images (about 70 a time). Some uianimations are running repeatingly. After a while my app show some performance lags (tested on a device). Xcode shows only 30MB of memory usage and about 97% CPU time used. Using instruments didnt really help (im not using a lot of memory anyway). How can I track this bug down, this seems so weird to me.
The problem is that using UIKit for such graphics is not the best solution, as it is working through CPU, not GPU. And this is the reason, why application is lagging.
The other reason for it to show only 30MB of memory used, as it does not show memory used for uncompressed images. When you display image on the screen, or use UIViews with drawRect:, it takes really a lot of memory.

performance issues with air app on iphone 4

Currently I am working on an Air app for iOS and Android. Air 3.5 is targeted.
Performance on iPhone 4 / 4s has been acceptable overall, after a lot of optimising: gpu rendering, StageQuality.LOW, avoiding vectors as much as possible etc. I really put a lot of effort in boosting performance.
Still, every once in a while, the app becomes very slow. There is no precise point in time or action or combination of actions after which this occurs. Sometimes, it doesn't occur for days. But when it occurs, only killing the app and launching it again helps, because the app stays slow after that. So I am not talking about minor hiccups that
The problem occurs only on (some) iPhones 4 and 4s. Not on iPad 3,4, iPhone 5, any Android device...
Has anyone had similar experiences and pointers as to where a solution might be found?
What happens when gpu memory fills up? Or device memory? Could this be involved?
Please don't expect Adobe Air to have performance as Native Apps. I am developing App with Adobe Air as well.
By the sound of your development experience. I think it's to do with memory issue, because the performance is not too bad at the begging stage, but it gets bad overtime (so u have to kill the app). I suggest you looking into memory leaking issue.
Hopefully my experience can help you.
I had a similar problem where sometime during gameplay the framerate would drop from 30fps to an unrecoverable 12fps. At first I thought I was running out of GPU memory and it was falling back on rendering with CPU.
Using Adobe Scout I found that when this occurred, the rendering time was ridiculousness high.
Updating to Air 3.8, I fixed the problem by limiting the amount of bitmaps that were being rendered and in memory at once. I would only create new instances of backgrounds for appropriate levels, and then flagging them for garbage collection when the level ended, waiting a few seconds and then moving to the next level.
What might solve your problem is if you reduce the amount of textures you have in memory at one time, only showing the ones you need to. If you want to swap out active textures for new ones, set all the objects with that texture data to null:
testMovieClip = null;
and remove all listeners from it so that garbage collection will pick it up.
Next, you can force garbage collection with AIR:
System.gc();
Instantiate the new texture you want to render a few frames after calling gc. Monitor resources with Scout and the iOS companion app to confirm that it's working.
You could also try to detect when the framerate drops, and set some objects to null then force garbage collection. In my case, if I moved my game to an empty frame for a few seconds with garbage collection, the framerate would recover and the game would resume rendering with GPU.
Hope this helps!

Responding to RAM availability in iOS

I have a texture-heavy OpenGL game that I'd like to tune based on how much RAM the device has. The highest resolution textures I have work fine on an iPhone 4 or iPad2, but earlier devices crash in the middle of loading the textures. I have low-res versions of these textures, but I need to know when to use them.
My current tactic is to detect specific older devices (3GS has a low-res screen; iPad has no camera), then only load the hi-res textures for IPad2 and above and iPhone 4 and above — and I suppose I'll need to do something for the iPod touch. But I'd much rather use feature detection than hard-coding device models, since model detection is fragile against future changes to APIs and hardware.
Another possibility I'm considering is to load the hi-res textures first, then drop and replace them with lo-res the moment I get a low memory warning. However, I'm not sure I'll get the chance to response; I've noticed that the app often dies before any notification appears on the debug console.
How do I detect whether the device I'm running on has insufficient RAM to load hi-res versions of my textures?
Taking a step back, is there some other adaptive technique I can use that's specific to OpenGL texture memory?
Notes:
I've searched on and off SO for answers related to available RAM detection, but they all basically advise profiling memory usage and eliminating waste (minimising the lifetime of temporaries, and all that guff). I've done as much of that as I can, and there is no way I am going to squeeze the hi-res textures into the older devices.
PVRTC isn't an option. The textures contain data to be used by fragment shaders and must be stored in a lossless format.
To get the total (maximum) physical RAM of the device use [NSProcessInfo processInfo].physicalMemory.
See Documentation.
Total physical RAM is available via sysctl(), as documented in this blog post and implemented as a nice clean API here (see the implementation of totalMemory in the corresponding .m file).
I've lifted the blog's code for convenience and posterity:
#include <sys/sysctl.h>
size_t phys_mem()
{
int mib[] = { CTL_HW, HW_PHYSMEM };
size_t mem;
size_t len = sizeof(mem);
sysctl(mib, 2, &mem, &len, NULL, 0);
return mem;
}
I don't know if Apple will approve an app that uses sysctl() in this manner. It is documented, but only for Mac OS X.
The most important think you need to know for memory management in this case is wether to use High or low res textures. The simplest way I use is to check this
CGFloat scale = [[UIScreen mainScreen] scale];
if ((scale > 1.0) || (self.view.frame.size.width > 320)) {
highRes = TRUE;
}
This works for all devices so far and should be future proof, newer devices will use the high res.
You might also calculate right there the aspect ratio (helps later on ipad vs iphone)
aspect = self.view.frame.size.width/self.view.frame.size.width
Don't load highres first it kills your apps load time, on my 3G most of my startup is spent loading (even the low res) textures, just test for this right at the beginning and don't touch the highres stuff.
On older devices the program will die without warning due to big textures, may have something to do with de debugger not being able to trap the video memory consumption and dying itself.
For greater optimizations consider tinting you mipmaps to check the lowest texture size that's actually being used (only if your using 3D objects).
Forget the video RAM size issue, memory is actually shared, so you're competing for system memory, on older devices you had a MB limit for use, but it's still system memory.
About memory management, there are many ways to do it, the simplest should be mark the textures that are loaded, and textures that are needed, when a memory warning comes, dump the textures that are loaded but not needed...
As far as I know the 3 most important things one can do is -
implement - (void)didReceiveMemoryWarning and respond when iOS sends warnings 1 & 2.
Profile code in Instruments trying to find leaks & better mem optimum ways of implementation.
Detect device types & maybe use that info.
Use some form of texture compressions like PVRTC to save space.
I think you are doing most of them. The thing is one does not even know accurately how much RAM iOS devices has. Apple does not publish tech specs for iOS devices.
Also, it cannot be assumed that only after say 100mb of consumption you will get a mem warning. The warnings that iOS gives varies depending on the current state of the device & what other apps are running & how much mem they are consuming. So it gets tricky.
I can suggest 2 must read sections - Best Practices for Working with Texture Data and Tuning Your OpenGL ES Application

Is there any way to accelerate iPad simulator's OpenGL performance?

iPad simulator is too slow to test OpenGL graphics. Is there any way to make it faster?
In my experience, the iPad Simulator has almost always been faster than running on an actual device. On my early 2010 i7 MacBook Pro, the Simulator has been significantly faster than the iPhone 4 and iPad 1 with almost every OpenGL ES application I've developed.
The Simulator does appear to do software-based simulation of certain iOS hardware features, particularly in the area of shaders. If you have a shader-heavy OpenGL ES 2.0 application, you can see a significant drop-off in performance when running in the Simulator.
In particular, the Simulator can't match the rendering speed of the iPad 2 when it comes to fill-rate-limited OpenGL ES applications, because the iPad 2 has a GPU that excels at this.
Beyond telling you to buy a faster computer, there's nothing that can be done to speed up the Simulator. As long as it has to simulate certain operations in software, you're going to get a little slower performance when doing certain types of rendering when compared to the very latest iOS devices. You're welcome to file an enhancement request at http://bugreport.apple.com to ask for performance improvements, but I don't know how much better the team at Apple can make this. They seem fairly conscious of performance issues from what I've seen.
As always, the Simulator should be used to test if something works at all, and all actual fine-tuning and anything else performance related should be done on actual hardware. I've found that the build-install-test cycle on the iPad 2 was almost as fast as dealing with the Simulator when I was developing my last application.

Resources