Teo
Teo

Reputation: 3442

IOS dealloc never gets called

I have a navigation-based app that switches between some ViewControllers. If I press the "goHome" button, the method popViewControllerAnimated: is called and I return to the main screen. There is a problem though : the dealloc method doesn't get called nor all the elements in that previous view get released. All the animations/UI elements remain hanging in the memory. What should I do?

Upvotes: 0

Views: 1919

Answers (2)

datayja
datayja

Reputation: 712

First, it’s a good idea to switch to Automatic Reference Counting, would make your life easier. Second, make sure that there is no more retained reference to the controller or other objects.

Funny story, once I forgot to set an NSFetchedResultsController’s delegate to nil and other memory errors and got an ugly exception when the fetched results controller tried to call the delegate, but it was already gone.

Upvotes: 1

Joseph DeCarlo
Joseph DeCarlo

Reputation: 3278

In your UIViewController make sure that your dealloc has the correct signature and is calling the super view last:

 - (void) dealloc {
     //Release your stuff
     [super dealloc];
 }

Also remember that when dealing with UIViewControllers you need to deal with memory in viewDidUnload as well (doesn't really address your issue, but thought I'd throw it in there).

Upvotes: 1

Related Questions