Question

I have a few tabs in my app. I am currently facing an issue whereby my pages gets unloaded whenever the memory gets low (especially if I bring up the camera in my app).

Is there anyway to mitigate this and prevent unloading from happening? Or is there any way to intercept the unloading process so that something can be done instead of allowing the page to be unloaded?

Was it helpful?

Solution

You should not prevent view unloading, if the application runs out of memory, it MUST free memory, or else your app will simply be killed by the system. You should really cleanup as much memory as you can, as well as views.

Also, views are only there to display data, if the view is unloaded it's only in one specific case: there was a memory warning and the view didn't have a superview (not visible to the user). If it's not visible to the user, it makes absolutely no sense to keep it around when running out of memory. If you're storing [important] data in these views, you're doing it wrong. Data model should be kept in controllers.

OTHER TIPS

When the memory gets low, all the view controllers get their delegate method: didReceiveMemoryWarning called.

The default implementation of UIViewController is to unload the view.

So, all you need to do in order to override this behavior is override the method:

- (void)didReceiveMemoryWarning
{
    //[super didReceiveMemoryWarning]; - calling this will unload the view

    // Relinquish ownership any cached data, images, etc that aren't in use.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top