How to respond to didReceiveMemoryWarning in an OpenGL application

My application has a lot of memory. It usually works fine, but on a loaded device that has not been restarted after some time, it will be reset with the notorious Low Memory error.

I would like to answer didReceiveMemoryWarning and free some of my caches.

But I have a problem that my application is based on the OpenGL ES template and does not have a view controller. It just has an application delegate that contains a link to glView.

What can I do to catch the didReceiveMemoryWarning message didReceiveMemoryWarning that I can respond?

+6
iphone opengl-es didreceivememorywarning
source share
2 answers

It is also available in application deletion .

 -(void)applicationDidReceiveMemoryWarning:(UIApplication *)application { NSLog(@"Received memory warning!"); } 
+9
source share

You can also add a method as an observer in any class you want to the notification UIApplicationDidReceiveMemoryWarningNotification . The code might look something like this:

 - (void) cleanMemory: (NSNotification*) notification { // Save memory! } - (id) init { // Or any other function called early on. // other init code [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cleanMemory:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; return self; } 
+10
source share

All Articles