I've been debugging some memory leaks. My understanding of Objective-C memory handling is, even now, flaky at best and this is not helped by retain count rules that include words like "generally" and "automatically" - in short I have no idea what the hell is going on.
What I want is to set the debugger to break on a retain and break on a release so I can see who or what is adding to the retain count. However, while you can set the debugger to break on a particular Objective-c invocation (such as setting a breakpoint on '-[NSException raise]' to effect a "break on exception"), doing this for a specific class is not possible.
Then I had this brainwave - just override the base class implementation by chucking the following into the .m file (no need to muck about with the headers):
CODE:
-(id)retain {
return [super retain];
}
-(oneway void)release {
return [super release];
}
...then set a breakpoint on whichever you want. Tadaa! Instance traceability of reference counts! It also acts as a just astounding way of learning what does and does not change the reference counts...