快速的一個人。快速瀏覽下面的代碼片段。我分配UILabel * textLabel但我不釋放它(註釋掉)。當方法結束時,我失去了指針的引用,所以它會泄漏。爲什麼儀器不能找到這個泄漏?
問題是XCode Instruments沒有發現這個泄漏,我會認爲它是一個非常簡單的情況下找到它。它沒有在我的應用程序中報告任何泄漏,但我自己發現了這一個,這讓我有點懷疑。
我是在看東西還是在檢測泄漏的儀器方面很差?
-(UITableViewCell*)newReadOnlyCellWithTitle:(NSString*)title andText:(NSString*)text {
UITableViewCell *cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text=title;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor whiteColor];
cell.opaque=YES;
UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(80, 11, 350, 24)];
textLabel.text=text;
textLabel.textColor=[UIColor lightTextColor];
textLabel.font=[UIFont fontWithName:STANDARD_FONT size:16.0];
textLabel.opaque=YES;
textLabel.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:textLabel];
//[textLabel release]; //<== without the release this should leak, yep?
return cell;
}
編輯:從靜態analyizer輸出...
構建和分析(CMD + SHIFT + B)應該找到它:) – cweinberger 2011-04-17 20:11:28
優秀的一點。靜態分析儀確實找到它! – Damien 2011-04-17 20:14:05
@theMikeSwan嗨,我想如果你把你的評論作爲答案,我會把它標記爲正確的。 – Damien 2011-04-17 22:08:18