At some point in my app I remove a view controller (let's call it A) from its parent view controller (let's call it B). And even though A is not referenced anymore, its dealloc method is not called.
I checked with instruments, A is really being freed. The number of living objects (of class A) is 0.
NSZombie is not enabled, I saw that it could interfere with dealloc calls.
The only moment the dealloc method is called, is when the view controller B is deallocated. At that moment, the stack trace is like that :
#0 0x0001ac78 in -[MyViewController dealloc] <-- This is A
#1 0x021061bf in _objc_deallocOnMainThreadHelper ()
#2 0x029f34d0 in _dispatch_client_callout ()
#3 0x029e1726 in _dispatch_main_queue_callback_4CF ()
#4 0x0274443e in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#5 0x026855cb in __CFRunLoopRun ()
#6 0x026849d3 in CFRunLoopRunSpecific ()
#7 0x026847eb in CFRunLoopRunInMode ()
#8 0x046095ee in GSEventRunModal ()
#9 0x0460942b in GSEventRun ()
#10 0x00db4f9b in UIApplicationMain ()
#11 0x00028ea2 in main at /../main.m:17
I am not sure how the dealloc is triggered
Any idea what can be happening here?
-- EDIT
I create the view controller A with a class method :
+ (instancetype)viewController
{
return [[MyViewController alloc] init];
}
The weird thing is that when I replace the call to this class method with [[MyViewController alloc] init] everything works as expected. I don't know what's happening. Any idea?