« Changing the disclosure triangle in an NSOutlineView | Main | Tiger and the keyboard »

June 17, 2005

Finding memory leaks with Object Alloc

So, your app leaks? Here's how to fix it:

1. Open your app in Object Alloc
2. Start the process, and check to have retain events:

Focus1

3. Run till in a known state

4. Check "Show since mark":

Focus2

5. Click auto-sort:

Focus3

6. Click the "Current" column header to sort on that automatically:

Focus4

7. Click the Mark button:

Focus5

7. Do the offending memory leak operation (to warm it up)
8. Click Mark again, and repeat the offending memory leak operation.

9. Take a look at the Instance Browser, and find your objects that are leaked:

Focus6

10. Pause the app, and in the right hand browser column will be the allocation events. Double click on them and you can see the stack of the allocation/retain/release event, and figure out who isn't "playing nice" by seeing who should have done a release for a corresponding alloc/retain/copy:

Focus8

Have fun!
--corbin

Posted by corbin at June 17, 2005 02:20 PM

Comments

Excellent tip. Welcome to the blogosophere. Always glad to see more Apple developers blogging.

Posted by: Justin Williams at June 17, 2005 07:52 PM

Post a comment




Remember Me?