【发布时间】:2011-05-29 22:05:43
【问题描述】:
我开始使用仪器并且有很多泄漏。我不知道如何解决它们。
仪器显示我在这一行有泄漏:
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? -
我修复了但没有解决问题
标签: iphone memory-leaks instruments