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:
2008-10-03 18:10:39.933 HelloWorld[1026:20b] *** -[GSFont ascender]: message sent to deallocated instance 0x126550
To activate the NSZombieEnabled facility in your application:
- Choose Project > Edit Active Executable to open the executable Info window.
- Click Arguments.
- Click the add (+) button in the “Variables to be set in the environment” section.
- Enter NSZombieEnabled in the Name column and YES in the Value column.
- Make sure that the checkmark for the NSZombieEnabled entry is selected.
iPhone 3.1 SDK introduces the Leaks instrument, which you can use in the Instruments application to easily find memory leaks. For more information, see Instruments User Guide.
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-05-28)
No comments:
Post a Comment