5

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.

Tariq
  • 9,861
  • 12
  • 62
  • 103
  • 1
    Is AController a subclass of UIViewController? Does it have a XIB file? If not, why are you initializing it with initWithNibName? – Stavash Feb 24 '12 at 13:54
  • maybe is your rootviewcontroller – alinoz Feb 24 '12 at 13:54
  • Maybe there is some property in AController that can't be released and that's rhy contr isn't dealloced? Could you post AController.h and AController.m? – Rok Jarc Feb 24 '12 at 14:01

6 Answers6

19

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.

Jake
  • 3,973
  • 24
  • 36
  • 5
    This is what I needed,In my non-ARC project non of my dealloc methods used to call.I used Instrument 'Allocations',selected 'created and still alive' ,changed Statistics to 'Objects list' ,notice 'Category' shows class name ,'Responsibility Library' check for 'app name' .Selecting arrow beside address will give detailed screen and make sure 'RefCount' reaches 0 – Alphonse R. Dsouza May 16 '13 at 15:14
  • for more easier debug you can give your class name some prefix and in the instruments->allocations search bar you can find project classes, saving debug time – maddy Apr 24 '14 at 07:15
7

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.

Sylvain G.
  • 508
  • 2
  • 9
2

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

Rambatino
  • 4,716
  • 1
  • 33
  • 56
1

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.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
RUppal
  • 71
  • 4
0

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

[[AController alloc]initWithNibName:nil bundle:nil]autorelease];
hariszaman
  • 8,202
  • 2
  • 40
  • 59
0

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.

Gobi M
  • 3,243
  • 5
  • 32
  • 47