release object of a return method object c

Posted by Piero on Stack Overflow See other posts from Stack Overflow or by Piero
Published on 2012-06-02T22:15:45Z Indexed on 2012/06/02 22:40 UTC
Read the original article Hit count: 242

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios