Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very strange behaviour of dealloc - not getting called

I have tested my all viewControllers dealloc methods. And all of them getting called properly on calling popViewControllerAnimated.

But only 1 controller's dealloc method not getting called. I am not able to figure out the issue.

While pushing to that controller I have properly written following code:

AController *contr = [AController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:contr animated:YES];
[contr release];

and when I am coming back from controller I have written :

[self.navigationController popViewControllerAnimated:YES];

This is really strange behaviour because this code is written on many controllers and its working properly.

like image 430
Tariq Avatar asked Feb 24 '12 13:02

Tariq


4 Answers

If it's not getting called it's still alive. Try to use instruments to find it. If you use the allocations tool in instruments you should be able to find the class (by name) in a list of allocations and see if it is still alive or not. You can even see by whom (I'm pretending that classes are people) it is retained.

like image 166
Jake Avatar answered Nov 03 '22 00:11

Jake


If dealloc is not called you might have another object that retain it.

Check that object that might use this delegate do not retain it.

like image 25
Sylvain G. Avatar answered Nov 03 '22 00:11

Sylvain G.


Hi I know this is an old post, but this answer may help someone stuck in my position. Spent a long time trying to find out why dealloc wasn't getting called. It turned out that I was not invalidating an NSTimer in my viewWillDisappear method and hence it was holding on to the retain count.

This great blog post is a must read for people in this situation:

http://www.reigndesign.com/blog/debugging-retain-cycles-in-objective-c-four-likely-culprits/#comment-41302

like image 28
Rambatino Avatar answered Nov 03 '22 01:11

Rambatino


I was having the similar issue;I wanted to show a UIViewController for like 3 seconds(copyright screen). So I was essentially calling the PushViewCOntroller and popViewController from the main file and the dealloc was not getting called when i was popping the view controller.

I then switched from pushViewCOntroller to

[self.navigationController presentModalViewController:copyrightView animated:NO];

and

[self.navigationController dismissModalViewControllerAnimated:NO];

and it started working.

I dont know how it can fix the issue; but it did.

like image 29
RUppal Avatar answered Nov 03 '22 00:11

RUppal