Question

I am developing an iPhone application which is navigation based. Whenever the application quits, the retain count of the navigation controller and the window is 3. Can somebody explain me how to overcome this issue? The dealloc method, as a result, is not getting called.

Was it helpful?

Solution

There is no issue.

  • You should try not to concern your self with retain counts unless you see a definitive leak (usually in Instruments)
  • You don't need to worry about objects like your window (and, probably, your nav controller) being dealloc'd at application quit-time; ALL of your app's memory will go away at that time.

OTHER TIPS

But none of the dealloc methods, neither for the UIViewController's nor the Appdelegate's are being called. The retaincount values of the view controllers are 1. The problem is, I retain them in a rootviewcontroller as they would be used again and again, and it would be lame to release them and allocate them again. So, when do I release these other UIViewControllers? The dealloc method of the rootviewcontroller is not being called.

You overcome this issue by not depending on dealloc methods being called. Application teardown code should go in the appropriate application methods. An object's dealloc should just do what's necessary to release that object's memory and fulfill its part in the memory management contract. When your app is terminated, all its memory is freed, so there's no need for dealloc to be called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top