Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent of -applicationDidReceiveMemoryWarning: on the Mac

I'm looking for an equivalent to the -(void)applicationDidReceiveMemoryWarning:(UIApplication *)application method that's available on the iPhone. So far I haven't been able to find anything, but I'd like to check before I start writing my own.

like image 291
Harry Jordan Avatar asked Oct 03 '09 16:10

Harry Jordan


Video Answer


1 Answers

Memory on Mac OS X doesn't work quite the same as OS X Touch. Notably, a desktop machine has lots more RAM and will swap memory to disk as apps demand more. As well, there are many applications competing for resources.

The real question is what are you trying to accomplish?

If the answer is use memory efficiently, then you need to focus on minimizing allocations, making sure you have no leaks, and ensuring that your data structures are optimized. Use ObjectAlloc in Instruments to analyze memory usage and figure out where to focus.

However, if the answer is more along the lines of I have a caching subsystem that benefits from lots of memory, but I want to give it back to the system when other apps increase their demands, then you'll want to investigate Snow Leopard's Caching and Purgeable Memory support.

Notably, the two APIs provide a means of aggressively caching data as long as their are system resources, backing off or giving back to the system when their is memory pressure.

like image 162
bbum Avatar answered Oct 27 '22 07:10

bbum