2010-02-09 67 views
0

这里我有一个疑问,我有一个MasterViewController,它没有Superview,我的标签是全局声明的,也用于不同的功能。 我的问题是如何释放分配的标签。如果我使用autorelease,那么它会生成异常。如何在MasterViewController中释放对象

- (id)init { 
    if(self = [super init]) { 

mview = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    //mview.backgroundColor=[UIColor clearColor]; 
    mview.autoresizesSubviews=YES; 
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,220,320,440) style:UITableViewStyleGrouped];  
    tableView.delegate = self; 
    tableView.dataSource = self; 
    tableView.rowHeight = 45; 
    tableView.backgroundColor = [UIColor clearColor];; 
    tableView.separatorColor = [UIColor blackColor]; 
    [tableView setSectionHeaderHeight:15]; 
    [tableView setSectionFooterHeight:10]; 
[mview addSubview:tableView]; 
} 
for example here I declared table view as global how can i release it?Is it possible to release in dealloc.I place a printf statement in dealloc but it was not displaying. 

Anyone's help will be appreciated. 

Thank you, 

Monish Kumar. 
+0

嘿家伙,请帮我这个。 – monish 2010-02-09 11:43:55

+0

你可以在这里发布一些代码吗? – Vladimir 2010-02-09 11:56:06

回答

0

首先,真的没有必要在全球范围内宣布如此之多的东西,实际上它只是作为最后手段使用的东西。所以我会尝试重做你的代码以避免这种情况。

这听起来像这一点,你真的需要运行在仪器的僵尸工具,使NSZombiesEnabled为YES环境变量,看看你的对象保留计数递增&递减,并且其中一个僵尸对象的第一个实例是messaged是。

你可以在这里看到一个这样的例子:http://www.corbinstreehouse.com/blog/2007/10/instruments-on-leopard-how-to-debug-those-random-crashes-in-your-cocoa-app/