I have the problem in an iOS app that after some time, an object isn't dealloc'ed as it should be. I suspect that this is because there is still a reference to it. I'm using ARC.
I want to find out where that reference is created. I will then be able to tell where it should be NULLed or if it should be made a weak reference.
What I imagine as a possible solution:
If I could set a breakpoint for every place where the reference count, aka retain count, is modified, then I will be quick to find the problem. I just don't know how to set such a breakpoint. Maybe at pre-ARC times, this could have been done by setting breakpoints inside retain
and release
, but I have no idea how to do this with ARC.
Highly simplified example code:
I've done this in one of my classes and I know where:
// ShouldBeDeallocated.m
- (void) dealloc {
NSLog(@"%s", __FUNCTION__); // this never shows up in output
}
And I suspect that I wrote code like this some time ago, but I can't find where that was:
// UnknownSuspect.m
@interface UnknownSuspect ()
@property (strong, readwrite) id referenceWhichIsNeverNeeded;
@end
- (void) someMethod:(ShouldBeDeallocated*)ref {
self.referenceWhichIsNeverNeeded = ref;
// The object pointed to by referenceWhichIsNeverNeeded will
// not be dealloc'ed unless the property gets overwritten.
}