开发者

How to prevent page from unloading when app is active

开发者 https://www.devze.com 2023-04-10 15:50 出处:网络
I have a few tabs in my app. I am currently facing an issue whereby my pages gets unloaded whenever the memory gets low (especi开发者_Python百科ally if I bring up the camera in my app).

I have a few tabs in my app. I am currently facing an issue whereby my pages gets unloaded whenever the memory gets low (especi开发者_Python百科ally 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?


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.


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.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消