I have spent some time debugging a weird issue with ARC and custom dealloc functions.
- I'm subclassing
NSOperation
class - 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
DataRequest
holds the ONLY reference to the operation I generate and is destroyed in the operation completion block. It's ALWAYS destroyed (itsdealloc
always 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
dealloc
are not printed. If I just quit the debugger and launch the app straight from the simulator - the Console.app show all messages. No compile no linking in between. Strange. – Xylo