-1

So, I got a little problem with my own UIViewcontroller subclass, it won't get deallocced when I press the back button on the navigation bar. I really have no idea why it won't even call the dealloc method. My other viewcontroller deallocs just fine. Has anyone encountered similar problem before? If you want me to post some code, say as I have no idea why it does this.

detailViewController *detailViewC = [[detailViewController alloc] init];
[detailViewC setItem:[items objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detailViewC animated:YES];
[detailViewC release];

My init method is here:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;

}

Samuli Lehtonen
  • 3,840
  • 5
  • 39
  • 49
  • don't you forget to call `[super dealloc]` in your own implementation ? –  Jul 24 '11 at 20:15
  • I am calling it, I even NSLog in my dealloc method and no luck. But strange thing is that when I push new instance of my own viewcontroller inside the one viewcontroller that won't dealloc. Then I press back on the newly pushed controller and it deallocs. Hope you got it. – Samuli Lehtonen Jul 24 '11 at 20:18
  • yes understood, post a bit of code, or check if you didn't retained it more than you need. –  Jul 24 '11 at 20:22
  • I commented down there. I will edit how I push it to my post. – Samuli Lehtonen Jul 24 '11 at 20:25
  • yes indeed, nothing really crazy, but post it in your question, it better to read it –  Jul 24 '11 at 20:27

1 Answers1

0

Code would be nice...

Anyway, if it does not deallocate, then (bar bad bugs in iOS) it must be because something is holding on to it.

Have you some other object (for instance another controller) that holds a reference to your controller in one of its retaining properties? That could be a relatively simple explanation.

Monolo
  • 18,205
  • 17
  • 69
  • 103
  • This is how I push it: detailViewController *detailViewC = [[detailViewController alloc] init]; [detailViewC setItem:[items objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:detailViewC animated:YES]; [detailViewC release]; – Samuli Lehtonen Jul 24 '11 at 20:23
  • Stupid question: Are you sure you don't over-retain in the init method? You must call a superclass' designated initialiser somewhere in your init method. What does that look like? – Monolo Jul 24 '11 at 20:28
  • Edited my init method to main post – Samuli Lehtonen Jul 24 '11 at 20:32
  • OK, that looks normal - actually, it does nothing as far as I can tell. Anyway, are you sure that it is a dealloc you need? Maybe you should use viewDidUnload:, which is pretty much guaranteed to be called when the controller is popped. It represents view hierarchy management, while dealloc is memory management, which may have different architectural implications. – Monolo Jul 24 '11 at 20:37
  • @Samuli Lehtonen - your edit suggests you might have written a `-(id)init;` method and call the superclass' designated initialiser as Manolo pointed out. –  Jul 24 '11 at 20:38
  • I haven't written -(id)init method. – Samuli Lehtonen Jul 24 '11 at 20:41
  • Sorry, my post crossed the edit, so I didn't see the code together. Like that, it doesn't look quite normal. I don't know, couldn't the init message just invoke the original init from NSObject? Are there any runtime checks that designated initialisers are actually called? – Monolo Jul 24 '11 at 20:43
  • If you don't call initWithNibName:bundle: , then how do you manage to see your nib file? – Monolo Jul 24 '11 at 20:45
  • When I put NSLog inside that method, it actually gets called. – Samuli Lehtonen Jul 24 '11 at 20:46
  • How about a breakpoint instead of NSLog - then you can see exactly which methods are higher up the call stack, and how it gets called, because that is a bit confusing, honestly. – Monolo Jul 24 '11 at 20:50
  • Should I try to make the -(id)init method? – Samuli Lehtonen Jul 24 '11 at 20:54
  • So when I put the breakpoint what should I look for as I haven't used many breakpoints before? – Samuli Lehtonen Jul 24 '11 at 20:59
  • Look at the method that called your initWith..., given that your own code doesn't do it. And the method that called that one, if needed. Try to figure out what is going on. – Monolo Jul 24 '11 at 21:02
  • I have located the problem now, it has nothing to do with the init thing, I actually place subviews in my scrollview, it deallocs if there is only one subview, but if there is more than one it won't. Strange huh? – Samuli Lehtonen Jul 24 '11 at 21:14