iOS memory warning sent to deallocated UIViewContr

2019-07-16 01:37发布

问题:

I have strange behavior. My application being launched with UINavigationController. If I push view controller ANavigationController, go back and simulate memory warning everything works good.

If I push the same view controller (ANavigationController) the same way, go back and simulate memory warning - application crashes with error:

[ANavigationController retain]: message sent to deallocated instance.

While debugging this I've printed addresses of pushed controller and deallocated one:

  1. On first push - pushed controller address is 0xDA724F0.
  2. If I go back and simulate memory warning - all ok.
  3. Second push - –dealloc method of controller with address 0xDA724F0 called.
  4. New pushed controller address is 0xFA720F0.
  5. Going back and simulating memory warning crashes with error:

    [ANavigationController retain]: message sent to deallocated instance 0xDA724F0.

Why deallocated controller (in step 4) gets memory warning message at all?

Edit

I'm using ARC.

Edit

After running Instruments to test allocations and enabling NSZombie i got crash in the expected place, however -1 reference count reported in UIkit library and responsible Caller is:

+[UIViewController _traverseViewControllerHierarchyWithDelayedReleaseArray:block:]

回答1:

I'm not sure whether this is a solution or a workaround for a problem but disabling ARC for this specific file resolved this problem. Of course I had to go and to manage memory by myself.

Still I'll appreciate any clue for what is the problem.

EDIT

Found a solution to this. Please see my answer to my other question: [UINavigationController retain]: message sent to deallocated instance