Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 814
Jonathan. Avatar asked Oct 22 '10 09:10

Jonathan.


People also ask

How to handle memory warning in iOS?

Remove references to any temporary objects that you no longer need. If active tasks might consume significant amounts of memory, pause dispatch queues or restrict the number of simultaneous operations that your app performs. Failure to reduce your app's memory usage may result in your app's termination.

What is memory warning?

onLowMemory() raises when the system global memory is low. If the global memory is okay but your process takes more than 24MB on old Android devices, it will crash and you'll never get a low memory warning.

How do I reduce memory usage on my iPad?

The two most common solutions to clear storage space on your iPad is to delete photos/videos from your photo library or to uninstall apps. Before you delete anything though, make sure that you know how to backup the files you would like to keep. For example, you can keep a backup of your photo library on iCloud.


1 Answers

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.

like image 148
Vladimir Avatar answered Oct 02 '22 14:10

Vladimir