简体   繁体   中英

Memory leaks in Instruments

I'm getting lots of leaks in my code, but none of the leaks point to any of my code (they are all UIKit methods).

I'm running 3.0.

Could someone tell me how I go about figuring out where these leaks are coming from?

Be careful about how you interpret the information about where the leaks occur. For example, it's not uncommon to leak "placeholder" strings -- default strings that are allocated early in object construction and then typically overridden by your own custom code. While you don't directly allocate the placeholders, you do need to handle the overriding correctly. In other words, the leaks are avoidable, and they are your fault, so to speak.

However, there are some leaks in the SDK. UIWebView definitely leaks a bit, for example.

Could you show us the call stack for the leak? ( Instruments/View/Extended Detail to see the stack. )

Thanks for helping out.

All I'm doing is loading a UITableView here. But I do call an asyncimageview class for icon loading, and am using a Singleton class for the datasource.

Anyway, all the leaks for each type (ie, GSEVENTs ) report the exact same detail. The item that doesn't show all the detail doesn't report any of my classes or methods BTW.

Here are the snapshots:

link text

I read somewhere about bugs in UIAccelerometer (which I need to use) that could cause the GSEVENT problems.

I paired down my cellforrow to the bare minimum, without any extra classes (except the singleton). Must be in the singleton then. I pretty much used the TheElements sample code to build that class.

Here is my cellForRowAtIndexPath now (even with this barbones, app still leaks, even when scrolling):

static NSString *myCell = @"myCell";
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:myCell];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:myCell] autorelease];
}
UILabel *l=[[[UILabel alloc] initWithFrame:CGRectMake(10,10,200,16)] autorelease];
l.backgroundColor=[UIColor blackColor];
l.font=[UIFont boldSystemFontOfSize:15];
l.textColor=[UIColor whiteColor];
l.text=[(NSDictionary *)[[News sharedNews].newsArray objectAtIndex:indexPath.row] objectForKey:@"text"];
[cell.contentView addSubview:l];

return cell;

Turned out to be the accelerometer. I removed it and the leaks disappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM