Reputation: 3273
iOS Devices use virtual memory with Paging . As the availability of the pages is limited by various factors such as the number of applications open , Allocations by different applications , etc. The application will terminate in cases when the rate of allocation by the application is exceeding the rate at which pages are being freed by other Applications. so, the OS asks the application to free memory. Unable to free the memory leads to the crash/terminate.
My question : is it possible to prevent app termination on Low device memory?
Upvotes: 0
Views: 645
Reputation: 92384
No, you cannot prevent the app termination.
As others have noticed, iOS warns you when memory is low and you can free some memory, if possible (a nice class that can aid with this is NSCache
which few people know: it's like a NSMutableDictionary
that can release content when memory gets low).
But if that is not enough, eventually the OS has no other choice and will kill your app. iOS first starts to kill apps in the background (which already should have saved their states), and only if there is really no other choice left the app in the foreground is killed: in that case you almost always have a programming error (like a memory leak).
Upvotes: 1
Reputation: 335
Every view controller will receive the low memory warnings.Please try any one of the following ways
1.overwrite the method -(void)didReceiveMemoryWarning on view controller
2.you can register your appropriate class for UIApplicationDidReceiveMemoryWarningNotificationnotification this notification
Note: app receive low memory warning only in main runloop. if main runloop busy at the time of low memory app will terminate without receiving the warnings.
Upvotes: 0
Reputation: 130
Yes, When low memory situation occurs then this method:
-(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
gets called. You can handle situation here.
Upvotes: 0
Reputation: 7639
Utilize - (void)didReceiveMemoryWarning
properly within your view controllers and you can help to prevent it since that method should fire prior to the app being terminated.
Upvotes: 0