iPhone app memory leaks from core frameworks
Are these kind of leaks normal? Are they false leaks or something I should be concerned with? The instruments tool doesn't give me any line of code from my app, seems Apple's frameworks are leaking?! alt text http://www.freeimagehosting.net/uploads/d50bdb5dec.png
Ok, the problems could only come from here:
(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"ProjectDetailView" bundle:[NSBundle mainBundle]];
Project *project = [projectsArray objectAtIndex:indexPath.row];
[detailViewController setProject:project];
[detailViewController setTitle:[project name]];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
OR from the detail view's viewWillAppear event:
(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[projectName setText:[project name]];
[appDefStatement setText:[project appDefStatement]];
[projectDesc setText:[project desc]];
NSMutableArray *theSketches = [[NSMutableArray alloc] initWithArray:[project.sketch开发者_开发问答es allObjects]];
[self setSketchesArray:theSketches];
[theSketches release];
if([sketchesArray count] == 0) {
[tView setHidden:YES];
} else {
[tView setHidden:NO];
}
}
There are very few cases where the leaks come from Apple's source code, so I would say first things first:
- Anytime you use
alloc
you need to release whatever object you created at a later, safe time - Make sure any objects that are synthesized in the .m file are released in dealloc call
- Read this helpful (albeit boring) article on memory management: http://developer.apple.com/iphone/library/documentation/cocoa/conceptual/memorymgmt/memorymgmt.html
- Walk through this great example on Leaks http://www.mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/
P.S. Without posting your code, we can only speculate... you'd get better answers by posting the suspect code.
Although is possible that somethings apple code has leaks, the fact that you see a leak there it doesn't mean that leaks is actually there. For instance, it could be that you alloc something from apple's framework and then you didn't release properly.
Hope this helps.
Greetings
I think these are false leaks. One of the leaks even shows up for a line of code taken from Apple's documentation (the line from cellForRowAtIndexPath that attempts to fetch a reusable cell). So my guess is the Leaks instrument is not perfect. I have checked my code a number of times and made sure I am releasing everything that has been alloced/copied/retained/mutableCopied etc etc.
精彩评论