views:

67

answers:

1

Please help, I don't know what I have to do with didReceiveMemoryWarning exactly. My app launched well, but when there is too many running background apps, it receives memory warning, and exit. I just want to show an alert that asks user to exit some background apps.

I have an appDelegate, in its window there is a view of my viewController, it has another view allocated (composite) with two subviews (a XIB over an OpenGL view), and this is set to be a cameraOverlayView in the viewController.

I tried to release the whole stuff in one at warning, but still exited. Do I have to implement didReceiveMemoryWarning in each subview? Can I somehow "forcequit" the initialization process?

+2  A: 

If your app is being terminated while it is active, then you probably have a memory leak causing your app to consume a large amount of memory.

When the OS starts running out of memory it will terminate background tasks first starting with the most memory intensive, then eventually the front-most app. The user never needs to manually terminate background apps to save memory. This is all done automatically.

If your app is in the background then it can be terminated at any time. The best you can do is reduce overall memory usage and hope the OS kills some other more memory intensive apps before yours.

didReceiveMemoryWarning is usually where you would release any cached data you have to try and reduce your app's footprint. Any view controllers in your app whose view isn't currently visible will be unloaded and the viewDidUnload method will be called. This is where you should set any IBOutlet properties to nil.

But again if your app is being terminated while it is active, you should use the Leaks tool in Instruments to make sure you don't have any leaks and you aren't consuming an abnormally large amount of memory.

Mike Weller
I'd also recommend using the Memory Monitor instrument to examine the real total size of your application. If it is spiking above 30 MB at some point, it will be force-terminated on older iOS devices, without any background processes.
Brad Larson
Thanks, useful. So my memory requirmentes are now 20 mb. This is an OpenGL scene with large textures. I cannot spare on its dimensions, only PVR compression saves memory, but requirmentes are Still 14 megs then. On my phone flightcontrol is the most memory exstensive app with 13 Mb. So i think my app is the most memory extensive, therefore it exits first. It has no runtime allocated objects, only at initialization, so i think i cannot find Any leaks. The memory consumption is at constant 20 megs, anything i do as a user. So what to do now?
Geri
A Process called springboard eats 27 megy, but it don't gets killed before mine. Maybe something system task.
Geri
@Geri - Springboard is the main application launcher on the iPhone. It is also where the Core Animation server is hosted, so memory related to views or other graphical elements within your application may actually show up there. Also, just because you don't see any leaks in the Leaks instrument or the Clang Static Analyzer does not mean there aren't any in your application. Look for steadily increasing memory within your application, which may also indicate faulty caches or the like. The new Heap Shot ability of Instruments can help you with this.
Brad Larson
I examined it with instruments already. By the way, I decided to trade some image quality to memory shrinking by 2bit PVR texture comression, and since then I couldn't reproduce application terminating. Maybe not the actual memory size, but the size of the blocks or whatever solved the problem. All in all, the stability is far better now. Thanks for the device/OS releated informations again, helped a lot.
Geri
Hmm... if I refresh the text of a label in about every seconds by text=@"The new value"; like assignments, then the previous NSString are being destroyed. Am I right?
Geri
Almost forget, take a look at the product if you like: http://gotoandplay.freeblog.hu/categories/compass3D/
Geri