简体   繁体   中英

ViewController never gets deallocated

In my mind, myViewController should be deallocated around the time that I pop back to the root view controller with the following code, but I never see the deallocation message getting NSLogged.

If this should work, then what kind of problem can I look for in the myViewController's class that might cause it to get deallocated when I popToRootViewController?

Thanks.

The following gets called in my tableView:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

MyViewController *vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

[self.navigationController pushViewController:vc animated:YES];

[vc release];
}

UPDATE:

This code was perfect, but it was some bad memory management in my custom view controllers that caused neither to be released. I had some retained properties that should have been assign instead (or at least, that's the way I solved it). See comments for specifics.

@JaySmith02 is right

it was some bad memory management in my custom view controllers that caused neither to be released. I had some retained properties that should have been assign instead (or at least, that's the way I solved it)

In my case the culprit was

@property (nonatomic, retain) id<TTSlidingPagesDataSource> dataSource;

From my viewController when I wrote

slidingPages.dataSource = self

I guess the dataSource retained my viewController and made a circular retention. The 'dealloc' of my viewController was never getting called.

Note: Under ARC dealloc does get called. Difference is you cannot call [super dealloc]

The solution:

@property (nonatomic, assign) id<TTSlidingPagesDataSource> dataSource;

When you use poptoviewcontroller then dealloc method will call for the topmost view controller in navigation controller. You can put a breakpoint in dealloc method of your current view controller and when you called popviewcontroller then your dealloc method gets called and release all the stuff/varaibles you have created in your view controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM