how can i solve this potential leak ?
- (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 tells me two problems with chapter.
Incorrect decrement of the reference count of an object that is not owned at this point.
Why is this object not owned by me ?Potential leak of an object.. (chapter)
How release it correctly?
[chapter autorelease]] ?