In Apple documentation you can find that Apple recommends to release heavy data like images when your app is entering to background mode.
How to release images from UIViews and an other data?
How to release images from UIViews from all viewController right way?
How to restore data when app get applicationWillResignActive message?
If somebody have a good example or link, please show it.
Add to app delegate 2 methods
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}
Make BaseViewController with methods:
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground) name:NOTIFICATION_APP_FOREGROUND object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground) name:NOTIFICATION_APP_BACKGROUND object:nil];
}
return self;
}
- (void)appDidBackground {
}
- (void)appWillForeground {
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Subclass all your view controllers from BaseViewController. In method appDidBackground you should release unneeded data, in appWillForeground - restore it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With