Xcode and ARC debugging problem (skipping dealloc)

I spent some time debugging a weird problem using ARC and custom dealloc functions.

  • I will subclass the NSOperation class
  • I set the completion block for this operation
  • The operation refers to the strong property of a flat object. It allows you to call this DataRequest object without methods, automatic ivars, two strong properties DataRequest
  • following all the recommendations, the completion block uses only weak references to local objects (including the operation itself).
  • neither the compiler nor the analyzer generate any problems.
  • DataRequest contains ONLY a link to the operation that I generate and destroyed in the operation completion block. It is ALWAYS destroyed (its dealloc always executed)
  • My operation has a custom dealloc . I have only one call to NSLog.

... and the problem:

If I run this in the debugger, the breakpoint in dealloc never hits, the log message never appears. First of all, I thought the operation was proceeding.

If I run this in the tools, everything is fine, the system console prints a message, and the Allocations tool reports that the operation is exempted from the snapshot of the stack, including the user dealloc. No leaks detected.

I am 100% sure that I use the same compiler settings for debugging and profiling.

The most confusing thing at the end: if I create a custom version of [DataRequest dealloc] , and I put self.operation = nil; on it self.operation = nil; - everything works fine even with a debugger.

Does anyone have any hints on what kind of compiler linker options they are trying to see to some extent? Could this be a mistake in Apple tools (we were all in a position blaming big fish for our mistakes, right?)

... and yes, I tried with GDB and LLDB. The result was the same - that could indicate something.

I tried to create a minimalist pattern, but it just worked (really);)

thanks

+7
source share
3 answers

Do you have NSZombiesEnabled? We had the same problem and "solved" by disabling NSZombies.

Product → Scheme → Change Scheme → Diagnostics → Uncheck Enable Zombie Objects

I'm not sure why dealloc is not called when NSZombies are turned on (I'm sure it was called before ARC).

+7
source

Today I came across the same issue, and I took about 5 hours to find out that the problem is caused by the fact that NSZombies is included in my project settings.

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

After many tests, it seems that dealloc is not called when using iOS 5.x (device or simulator).

but it is called again (with Zombies turned on) in iOS 6.x (device or simulator)

I do not know if this is caused by a change in the error in ios5, which was fixed in ios6, or by the introduced function and rollback.

Hope this helps ...

+1
source

Today I came across the same question, but my problem was the save loop generated by the block.

If you use blocks:

  • Make sure SELF is not displayed inside the block.
  • If you need to use SELF inside a block, use a weak link.
  • Make sure that there are no macros inside the block that can reference self (for example, NSAssert).
0
source

All Articles