ViewController永远不会被释放 [英] ViewController never gets deallocated
问题描述
在我看来,应该在使用以下代码弹出根视图控制器的同时,将myViewController释放,但是我再也看不到释放消息出现NSLogged.
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.
如果这行得通,那么我在myViewController的类中会寻找什么样的问题,而当我弹出popToRootViewController时,该类问题可能导致它被释放?
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?
谢谢.
在我的tableView中调用以下内容:
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];
}
更新:
这段代码很完美,但是由于我的自定义视图控制器中的一些内存管理不善,导致两者均未释放.我有一些保留属性应该改为分配(或至少是我解决它的方法).有关详细信息,请参见评论.
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是正确的
@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)
在我看来,罪魁祸首是
@property (nonatomic, retain) id<TTSlidingPagesDataSource> dataSource;
从我写的时候的viewController
From my viewController when I wrote
slidingPages.dataSource = self
我猜想 dataSource
保留了我的 viewController
并进行了循环保留.我的 viewController
的'dealloc'从未被调用过.
I guess the dataSource
retained my viewController
and made a circular retention. The 'dealloc' of my viewController
was never getting called.
注意:确实在ARC下调用了
dealloc
.区别在于您无法调用[super dealloc]
Note: Under ARC
dealloc
does get called. Difference is you cannot call[super dealloc]
解决方案:
@property (nonatomic, assign) id<TTSlidingPagesDataSource> dataSource;
这篇关于ViewController永远不会被释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!