release object of a return method object c
- by Piero
in run the app with the analyze build, and Xcode found me a lot of memory leak and there is one in particular that i don't know how solve here it is:
- (UIView *) tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
UIImageView *sectionImage = [[UIImageView alloc] init];
if (section == 0)sectionImage.image = [UIImage imageNamed:@"myImage.png"];
return sectionImage;
}
so my question is, how i can release this sectionImage? if is the return of the method?
EDIT:
i have another question, analyze give me another memory leak, i have this:
.h
@property (nonatomic, retain) NSIndexPath *directCellPath;
.m
@synthesize directCellPath = _directCellPath;
- (id)init{
if ((self = [super initWithNibName:@"MyViewController" bundle:nil])) {
self.directCellPath = [[NSIndexPath alloc] init];
}
return self;
}
then in the code i use it and finally in the dealloc i do this:
- (void)dealloc {
[_directCellPath release];
[super dealloc];
}
and give me a memory leak on this line:
self.directCellPath = [[NSIndexPath alloc] init];
why if i have deallocated it in the dealloc?