2012-07-13 52 views
0

我在xcode中使用了分析功能,并且我已经修复了除此之外的所有内容。不明白潜在的泄漏

我想知道这是什么意思“潜在的泄漏对象分配”,它是指这些行。

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

self.type_prod = [[ProductType alloc] initWithNibName:@"ProductType" bundle:[NSBundle mainBundle]]; 

NSString *prodtitle = [product objectAtIndex:indexPath.row]; 
    type_prod.prodtitle = prodtitle; 

etc etc. 

在这一空白结束时,我说:

[[self navigationController] pushViewController:type_prod animated:YES]; 
[type_prod release]; 

那么,为什么它说有一个潜在的泄漏,如果我在最后释放呢?

+0

[ProductType页头] = 1保留计数 self.type_prod + 1 [type_prod发布] - 1 – VenoMKO 2012-07-13 17:49:05

+0

我明白我的保留数为1,因为我的Alloc,但由于我释放它,它会是1-1 = 0(至少这是我的想法)。但事实证明,self.type_prod增加其保留计数+1? – Prastow 2012-07-14 15:35:45

+0

我想你的保留数是2 self.type_prod最有可能使用保留。 – VenoMKO 2012-07-14 15:38:53

回答

1

我假设type_prod是一个保留属性。你需要在dealloc方法中使用self.type_prod = nil来释放它。

还要确保在所有情况下都会执行最后的版本。它是安全的自动释放它的时候了:

self.type_prod = [[[ProductType alloc] initWithNibName:@"ProductType" bundle:[NSBundle mainBundle]] autorelease]; 
+0

我像你说的那样放在autorelease中,并且在void的末尾我改变了[type_prod release]; self.type_prod = nil。因为我有一个autorelease,我假设我不需要在self.type_prod = nil之前发布一个版本,对吧?是否有必要[type_prod release];在 - (void)dealloc中?我很难理解自我的概念。 – Prastow 2012-07-14 15:33:50

+0

如果你的autorelease像我在我的回答中所说的那样,那么你不能在方法中再次释放伊娃。在dealloc中释放self.type_prod = nil是必要的。这与[self setType_prod:nil]是一样的。 – Felix 2012-07-14 19:41:13

+0

谢谢,我现在修好了! – Prastow 2012-07-15 00:48:53