I'm currently working on fixing some iOS 7 display issues on a legacy app which was not built with ARC, and have run into some inconsistent behaviour with the dealloc
method between iOS versions 6 & 7. I can't find any other mention of these changes in any documentation or community discussions, so I wonder if anyone here could shed some light on what's happening here?
My previous code, (which works in iOS6, looks like this):
@interface MyViewController()
@property (retain) AdHandler *adHandler;
@end
@implementation MyViewController
@synthesize adHandler = _adHandler;
- (id) initWithAdHandler:(AdHandler*)anAdHandler
{
self = [super init];
_adHandler = [anAdHandler retain];
return self;
}
- (void)dealloc
{
[super dealloc];
[_adHandler release];
_adHandler = nil;
}
...
@end
When stepping through the code in iOS 6, I've found that after the dealloc
statement, [_adHandler retainCount]
is still positive, and the object is still available.
In iOS 7 however, after the dealloc
statement, retainCount
has somehow hit zero, and the _adHandler
object has been dealloc
'd, and therefore my call to release
causes an EXC_BAD_ACCESS
.
I can fix this simply by moving my [adHandler release]
call to before the dealloc
call, but my question is why is this happening? Why is dealloc
releasing objects that it has no responsibility for? Is there any documentation anywhere on why dealloc behaviour has changed in this way?