Reputation: 1087
Any idea why this code gives me a memory leak? As you can see, I'm running out of ideas as to what I can do to stop it.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSArray *allSketches = [project.sketches allObjects];
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:allSketches];
if(sketchesArray != nil) [sketchesArray release];
[self setSketchesArray:temp];
[allSketches release];
allSketches = nil;
[temp release];
temp = nil;
}
I also release sketchesArray inside viewDidDissapear. I'm not using viewDidLoad and dealloc to init/release these objects as what I am doing requires me to use viewWillAppear and viewDidDissapear.
Thanks
Upvotes: 0
Views: 166
Reputation: 9543
I can't see the leak, but you've got a couple of probable over-releases.
The release of a non-nil
sketchesArray
should be managed inside setSketchesArray
. And it doesn't look like you have local ownership of allSketches
either...
Upvotes: 0
Reputation: 1087
Fixed it by using this instead:
NSArray *allSketches = [project.sketches allObjects];
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:allSketches];
[self setSketchesArray:temp];
[temp release];
Though I remember doing that and it didn't work before... Strange... There appear to still be some memory leaks coming from CoreGraphics though. Is that normal?
Upvotes: 1
Reputation: 13175
Is this being released somewhere else when you are done with it?
[self setSketchesArray:temp];
Specifically, you are releasing sketchesArray in this function, but do you do that elsewhere when you are done with the view?
Upvotes: 0