Tariq
Tariq

Reputation: 9979

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.

Upvotes: 5

Views: 8207

Answers (6)

Gobi Manickam
Gobi Manickam

Reputation: 3267

In my case, i have assigned circular ref object type with strong reference. Changing to weak type fixed this issue. Try getting which object retained in memory using Instruments as said in other answers.

Upvotes: 0

hariszaman
hariszaman

Reputation: 8424

For me using autorelease when allocating viewcontroller worked hope this helps someone

[[AController alloc]initWithNibName:nil bundle:nil]autorelease];

Upvotes: 0

Rambatino
Rambatino

Reputation: 4914

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

Upvotes: 2

RUppal
RUppal

Reputation: 71

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.

Upvotes: 1

Sylvain G.
Sylvain G.

Reputation: 508

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.

Upvotes: 7

Jake
Jake

Reputation: 3973

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.

Upvotes: 19

Related Questions