我開始使用儀器,並且有很多泄漏。我不知道如何解決它們。很多儀器上的奇怪泄漏只在設備上(模擬器中沒有泄漏)
儀器證明我有泄漏在這行:
NSArray *topLevelObjects = [[NSArray alloc] initWithArray:[[NSBundle mainBundle] loadNibNamed:@"SearchResultsTableViewCell" owner:self options:nil]];
有什麼不對呢?
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SearchResultsTableViewCell";
SearchResultsTableViewCell *cell = (SearchResultsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSArray alloc] initWithArray:[[NSBundle mainBundle]
loadNibNamed:@"SearchResultsTableViewCell"
owner:self options:nil]];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (SearchResultsTableViewCell *) currentObject;
break;
}
}
[topLevelObjects release], topLevelObjects = nil ;
}
Product *product = [productMutableArray objectAtIndex:indexPath.row];
cell.textLabel.text = product.title;
cell.detailTextLabel.text = product.desc1;
UIImageView *imageView = nil;
if (product.photo == nil) {
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ph38x38.jpg"]];
} else {
imageView = [[UIImageView alloc] initWithImage:product.photo];
}
imageView.frame = CGRectMake(10., 3., 38., 38.);
[cell addSubview:imageView];
[imageView release];
return cell;
}
我也有很多其他的泄漏,但儀器甚至不顯示行的代碼,例如有泄漏: GenerlaBlock-64 - UIKit中 - GetContextStack 我怎樣才能解決呢?我應該在哪裏尋找它?
我找了某種教程,但他們都表示只保留計數,分配繁瑣的例子,釋放
爲什麼你需要`initWithArray:`的東西,已經是一個自動釋放`NSArray`? – BoltClock 2010-12-23 11:10:26
我修好了但沒有解決問題 – woojtekr 2010-12-23 12:04:25