Search code examples
iphoneopengl-esdidreceivememorywarninglow-memory

How to respond to didReceiveMemoryWarning in OpenGL app


My app uses a lot of memory. Normally it runs fine, but on a loaded device that hasn't been restarted in awhile, it will be jettisoned with the infamous Low Memory error.

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

But I have the problem that my app is based off of the OpenGL ES template and doesn't have a view controller. It just has the App Delegate which holds a reference to the glView.

What can I do to trap the didReceiveMemoryWarning message so that I can respond?


Solution

  • This is also available within your Application Delegate.

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