Joey
Joey

Reputation: 7527

Tracking object retain calls

How do I track what is retaining my object? I have an object that isn't delloc-ing as expected when it is removed from a list. My suspicion is that something is incrementing the retain count, so I'd like to know how I can ideally create a place to break into the code anytime that object's retain count is incremented.

Upvotes: 1

Views: 460

Answers (1)

bbum
bbum

Reputation: 162712

The best possible answer is to use Instruments; it'll track retains/releases all day long.

http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/

If desperate, override -retain to simply return [super retain];. That'll give you a method you can conveniently set a breakpoint on. You could then use breakpoint commands to do something like:

bt
continue

That'll cause the debugger to spew the backtrace of every call, when hit, and then continue.

Upvotes: 2

Related Questions