开发者

Xcode and ARC debugging issue (skipping dealloc)

开发者 https://www.devze.com 2023-04-13 05:51 出处:网络
I have spent some time debugging a weird issue with ARC and custom dealloc functions. I\'m subclassing NSOperation class

I have spent some time debugging a weird issue with ARC and custom dealloc functions.

  1. I'm subclassing NSOperation class
  2. I set completion block for this operation
  3. The operation is referenced by a strong property of very flat object (no methods, automatic ivars, two strong properties) lets call this object DataRequest
  4. following all guidelines the completion block uses only weak references to local objects (including the operation itself)
  5. neither compiler nor analyzer generate any issues
  6. DataRequest holds the ONLY reference to the operation I generate and is destroyed in the operation completion block. It's ALWAYS destroyed (its dealloc always executed)
  7. 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 t开发者_开发问答ools (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).


I ran into the same kind of issue today and I took me about 5 hours to find that the problem was caused by NSZombies enabled in my project settings.

I also agree that before ARC, dealloc was called in this case.

After many tests it appears that dealloc is not called if using iOS 5.x (device or simulator).

but it gets called again (with Zombies enabled) in iOS 6.x (device or simulator)

I don't know if this change is caused by a bug in ios5 that has been patched in ios6, or a feature introduced and rolled back.

Hope that helps...


I ran into the same kind of issue today but my problem was a retain cycle generated by a block.

If you're using blocks:

  1. Make sure SELF doesn't appear inside the block.
  2. If you need to use SELF inside a block, use a weak reference.
  3. Make sure there are no macros inside the block that may be referencing self (like NSAssert).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号