我該如何解決這個潛在的泄漏?這個對象爲什麼是潛在的泄漏?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
Chapter *chapter =[Chapter alloc] ;
switch (indexPath.section) {
case 0:
chapter = [einfuerung objectAtIndex:row];
break;
case 1:
chapter = [vertiefung objectAtIndex:row];
break;
case 2:
chapter = [spezial objectAtIndex:row];
break;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:[chapter urlOnFilesystem]]) {
dataInstance.chapter = chapter;
Container *container = [[Container alloc] init];
[self.navigationController pushViewController:container animated:YES];
[container release];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Kapitel nicht vorhanden" message:@"Kapitel wurde noch nicht heruntergeladen" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
[chapter release];
}
Xcode告訴我有關章的兩個問題。
此時不擁有的對象的引用計數遞減不正確。
爲什麼這個對象不屬於我?對象的潛在泄漏..(章節)
如何正確釋放它?
[chapter autorelease]]?
@Jhaliya:你想在你的代碼引用中刪除'chapter'的第一個定義。 – DarkDust 2011-06-06 11:26:46
@ DarkDust:明白了。現在更新了答案。 – Jhaliya 2011-06-06 11:30:03
還有問題。如果你已經在默認情況下使用了,那麼你需要發佈。但在其他情況下,如果您從數組中獲取對象,則不應該釋放,因爲您不擁有該對象。 – taskinoor 2011-06-06 11:31:32