Search code examples
iphoneuiviewcontrollernsobjectlow-memory

Low memory warning for NSObject


I have a subclass of NSObject, it is a singleton which loads a list of images into memory, either from hard drive or downloads them from the internet.

I want to release the images stored in memory if the app recieves a low memory message, like in a UIViewController. (it then gets the images from hard drive when it next needs them).


Solution

  • You can implement -applicationDidReceiveMemoryWarning: method in your application delegate and free memory there. Or you can make your singleton object listen to UIApplicationDidReceiveMemoryWarningNotification notification and free memory in notification handler.