Iphone 仅在设备上的仪器中存在大量奇怪的泄漏(模拟器中无泄漏)

Iphone 仅在设备上的仪器中存在大量奇怪的泄漏(模拟器中无泄漏),iphone,memory-leaks,instruments,Iphone,Memory Leaks,Instruments,我开始使用仪器,有很多泄漏。我不知道如何解决它们 仪表显示该管线有泄漏: NSArray *topLevelObjects = [[NSArray alloc] initWithArray:[[NSBundle mainBundle] loadNibNamed:@"SearchResultsTableViewCell" owner:self options:nil]]; 这有什么问题 // Customize the appearance of table view cells. - (UIT

我开始使用仪器,有很多泄漏。我不知道如何解决它们

仪表显示该管线有泄漏:

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;
}
我还有很多其他的泄漏,但仪器甚至没有在代码中显示行,例如有一个泄漏: GeneralLock-64-UIKit-GetContextStack 我怎样才能解决它?我应该在哪里找它


我找了一些教程,但它们都只显示了一些简单的例子,包括retaincount、alloc、release

为什么不删除
initWithArray:
并使用

NSArray *topLevelObjects = [[NSBundle mainBundle]
         loadNibNamed:@"SearchResultsTableViewCell"
         owner:self options:nil];
(您必须删除
释放
并设置
行)


//编辑:尝试设置
所有者:nil

线程产生所有问题。我一直在做叉子,没有回到主线。这就是问题所在。

线程不是真正的问题。这是UILabel的“文本”属性

cell.textLabel.text = product.title;
cell.detailTextLabel.text = product.desc1;
此属性只能在主线程上设置。

改为调用performSelectorOnMainThread:

[cell.textLabel performSelectorOnMainThread:@selector(setText:) withObject:product.title waitUntilDone:NO];
[cell.detailTextLabel performSelectorOnMainThread:@selector(setText:) withObject:product.desc1 waitUntilDone:NO];

为什么您需要使用已自动删除的
NSArray
文件
initWithArray:
?我修复了它,但没有解决问题。仪器仍然显示相同的漏洞:(如果从nib加载,为什么要创建UIImageView?可以在nib中指定ImageView并将其与ViewController连接。然后每次创建单元格时都必须将其分配给init,而只需设置属性cell.myImageView.image=[UIImage ImageName:@“superimage.jpg”];你是对的,但它仍然没有解决问题。我仍然有漏洞:GSFontGetFamilyName、GetFontNames、GSFontGetFullName、getContextStack、WebThreadCurrentContext。带有字体的是用同一行连接的,loadnib检查所有漏洞,看看是否可以绕过所有alloc init语句。例如,NSString的对对我来说。如果我允许初始化一个字符串,使用它,然后释放它,如果不复制它,我将获得EXC_BAD_访问权限。也许你的其他泄漏来自其他任何地方,编辑:set owner:nil没有其他与代码相关的泄漏。我找不到任何东西,可以连接。真的很奇怪。你能详细说明一下吗?嗯,那是很久以前的事了,我不记得了。我想这是和线程和UI有关的(不能在线程中修改UI)。多个线程也有问题。我在该线程中启动新thred启动新thred等等,但没有返回到主线程。这是一个简单而愚蠢的错误。我遇到了一个类似的问题,并在绝望中尝试了上述解决方案。它没有解决我的问题。我没想到会这样,因为我很确定iOS已经读过了y从主线程调用tableView:cellForRowAtIndexPath。毕竟,它是UIKit的一部分,UIKit调用只能在主线程上进行。我缺少什么吗?