Finding Memory Leaks If you fix a leak and your program starts crashing, your code is probably trying to use an already-freed object or memory buffer. To learn more about memory leaks, see Finding Memory Leaks. You can use the NSZombieEnabled facility to find the code that accesses freed objects. When you turn on NSZombieEnabled, your application logs accesses to deallocated memory, as shown here:http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/iPhone_Development.pdf, page 55 Also, from Hillegass suggests to set the CFZombieLevel to 16. Cocoa Programming for OSX, 3rd Edition. Page 92
2008-10-03 18:10:39.933 HelloWorld[1026:20b] *** -[GSFont ascender]: message sent to deallocated instance 0x126550To activate the NSZombieEnabled facility in your application: 1. Choose Project > Edit Active Executable to open the executable Info window. 2. Click Arguments. 3. Click the add (+) button in the “ Variables to be set in the environment” section. 4. Enter NSZombieEnabled in the Name column and YES in the Value column. 5. Make sure that the checkmark forthe NSZombieEnabled entry is selected.
Remove observer before deallocating, otherwise observer accumulate and eventually crash the application.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[UIImage imageNamed:@"image.jpg"]caches image for lifetime of app.
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]no caching, always loaded from memory. after caching, faster display problem, running out of memory