Very strange behaviour of dealloc - not getting called
Asked Answered
A

6

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.

Accumulate answered 24/2, 2012 at 13:49 Comment(3)
Is AController a subclass of UIViewController? Does it have a XIB file? If not, why are you initializing it with initWithNibName?Assuage
maybe is your rootviewcontrollerPushup
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?Flour
C
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.

Consanguinity answered 24/2, 2012 at 13:51 Comment(2)
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 0Polarity
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 timeInebriate
T
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.

Thill answered 24/2, 2012 at 13:53 Comment(0)
C
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

Crossbill answered 29/5, 2014 at 12:18 Comment(0)
D
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.

Dratted answered 8/8, 2012 at 17:9 Comment(0)
L
0

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

[[AController alloc]initWithNibName:nil bundle:nil]autorelease];
Leptophyllous answered 5/9, 2014 at 14:44 Comment(0)
C
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.

Cervantez answered 6/11, 2015 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.