I have spent some time debugging a weird issue with ARC and custom dealloc functions.
- I’m subclassing
NSOperationclass - I set completion block for this operation
- The operation is referenced by a strong property of very flat object (no methods, automatic ivars, two strong properties) lets call this object
DataRequest - following all guidelines the completion block uses only weak references to local objects (including the operation itself)
- neither compiler nor analyzer generate any issues
DataRequestholds the ONLY reference to the operation I generate and is destroyed in the operation completion block. It’s ALWAYS destroyed (itsdeallocalways executed)- My operation has a custom
dealloc. I have only a single NSLog call in it.
… and the issue is:
If I run this under in debugger, the breakpoint in the dealloc is never hit, the log message never appears. Primarily I thought the operation was leaking.
If I run this in instruments, all is fine, the system console prints the message and Allocations instrument reports the operation being freed from the proper stack snapshot including the custom dealloc. No leaks detected.
I’m 100% sure I use the same compiler settings for debugging and for profiling.
The most confusing thing at the end: If I create a custom version of [DataRequest dealloc] and I put self.operation = nil; to it – all works fine even from the debugger.
Does anybody have some hints what compiler linker options to try to see some difference? can this be bug in Apple tools (all of us were in the position blaming a big fish for our own errors, right?)
… and yes I have tried with GDB and LLDB. Result was the same – what might indicate something.
I have tried to create a minimalistic sample but it just worked (indeed) 😉
Thanks
Do you have NSZombiesEnabled? We had the same issue and “solved” it by disabling NSZombies.
“Product” -> “Scheme” -> “Edit scheme” -> “Diagnostics” -> Uncheck “Enable Zombie Objects”
I’m not sure why dealloc isn’t called when NSZombies are enabled (I’m pretty sure it was called before ARC).