2011/05/26

Tracing Objective-C Allocation

So, let's say you have a problem tracking down some pesky retain/autorelease issue in your code. You can use NSZombieEnabled to catch double-releases, but sometimes those happen inside somebody else's code, and it's hard to track it down.

Based on a code I've found in this blog post, I've wrote a template for subclassing somebody else's class to print out the allocation history.

Here's how it looks:



And here's how you use it (in this example, I want to track AVPlayer):


SYNTESIZE_TRACE(AVPlayer)

AVPlayer* p = [[TraceAVPlayer alloc] init];


All done. Now, while running, you'll get a record of all retainCount modifications, with their stack trace.

No comments:

Post a Comment