I need that instance of my class observe property of itself, so I set observing:
[self addObserver:self forKeyPath:@"myProperty" options:NSKeyValueObservingOptionNew context:nil]
And in dealloc simply check and remove observer:
- (void)dealloc
{
if ([self observationInfo])
{
[self removeObserver:self];
}
}
This project is under ARC and all work fine prior to iOS 6 SDK. But with iOS 6 SDK, getting observationInfo
increase retainCount of object and app crashes after dealloc
with EX_BAD_ACCESS (release message sent to deallocated instance).
What is wrong in this code? Is it Apple`s BUG or mine?
UPDATE There is stacktrace:
thread #1: tid = 0x1f03, 0x016b60ab libobjc.A.dylib`objc_release + 27, stop reason = EXC_BAD_ACCESS (code=1, address=0xff000002)
frame #0: 0x016b60ab libobjc.A.dylib`objc_release + 27
frame #1: 0x016b6bd9 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 555
frame #2: 0x02538468 CoreFoundation`_CFAutoreleasePoolPop + 24
frame #3: 0x0253cafd CoreFoundation`__CFRunLoopRun + 1933
frame #4: 0x0253bf44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #5: 0x0253be1b CoreFoundation`CFRunLoopRunInMode + 123
frame #6: 0x024f07e3 GraphicsServices`GSEventRunModal + 88
frame #7: 0x024f0668 GraphicsServices`GSEventRun + 104
frame #8: 0x0022e65c UIKit`UIApplicationMain + 1211
frame #9: 0x00001efd MyProjects`main + 141 at main.m:16