Why this kind of release doesn't work?

Posted by parkyprg on Stack Overflow See other posts from Stack Overflow or by parkyprg
Published on 2010-05-22T14:08:06Z Indexed on 2010/05/22 14:10 UTC
Read the original article Hit count: 152

Hello,

I have a newbie question about the following:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSArray *anArray;
    anArray = [dictionary objectForKey: [NSString stringWithFormat:@"%d", section]];
    //here dictionary is of type NSDictionary, initialized in another place.
    AnObject *obj = [[AnObject alloc] init];
    obj = [anArray objectAtIndex:0];
    [anArray release];
    return obj.title;
}

If I run it as it is I will get an error. If I don't put [anArray release] it works just fine. I don't quite understand why is this happening?

Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c