目标C:如何解决代码泄漏(仪器结果)

我运行我的应用程序(其中包含一个UITableView)的仪器,并得到以下结果

每当单元格变为可见时,单元格将调用方法[UICustomButton SetButtonWithAnswer ….]

编辑:添加更多的截图

在这里输入图像说明

在这里输入图像说明在这里输入图像说明在这里输入图像说明在这里输入图像说明

问题是我不确定究竟是什么导致了泄漏。 我已经释放了所有我的代码中的分配inits。 为什么还在漏水?

任何意见,将不胜感激!

编辑:

我添加了UICustombutton如下

if (cell == nil) { cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier] autorelease]; //Add like button UICustomButton *likeButton = [[UICustomButton alloc]init]; likeButton.tag = 7; //Add comment button UICustomButton *commentButton = [[UICustomButton alloc]init]; commentButton.tag = 8; //Add answer too button UICustomButton *answerButton = [[UICustomButton alloc]init]; answerButton.tag = 9; [self.contentView addSubview:likeButton]; [self.contentView addSubview:commentButton]; [self.contentView addSubview:answerButton]; [likeButton release]; [commentButton release]; [answerButton release]; } //Set like button UICustomButton *thisLikeButton = (UICustomButton *)[self.contentView viewWithTag:7]; [thisLikeButton setButtonWithAnswer:self.answerForCell buttonType:@"like" navcon:self.navcon andFrame:CGRectMake(CELL_TEXT_LEFT_MARGIN, totalCommentLabelHeight + CELL_SPACING*4, 45, CELL_BUTTON_HEIGHT)]; thisLikeButton.imageView.image = [UIImage imageNamed:@"heart.png"]; //Set comment button UICustomButton *thisCommentButton = (UICustomButton *)[self.contentView viewWithTag:8]; [thisCommentButton setButtonWithAnswer:self.answerForCell buttonType:@"comment" navcon:self.navcon andFrame:CGRectMake(CELL_TEXT_LEFT_MARGIN + 45 + 5, totalCommentLabelHeight + CELL_SPACING*4, 80, CELL_BUTTON_HEIGHT)]; thisCommentButton.imageView.image = [UIImage imageNamed:@"chat.png"]; //Set answer button UICustomButton *thisAnswerButton = (UICustomButton *)[self.contentView viewWithTag:9]; [thisAnswerButton setButtonWithAnswer:self.answerForCell buttonType:@"join in" navcon:self.navcon andFrame:CGRectMake(1.5*CELL_TEXT_LEFT_MARGIN + 45 + 5 + 80 + 5, totalCommentLabelHeight + CELL_SPACING*4, 60, CELL_BUTTON_HEIGHT)]; thisAnswerButton.imageView.image = [UIImage imageNamed:@"beer-mug_white.png"]; 

setButton:…每个alloc / init都需要重新思考。 您不想重新创build这些视图来设置值。

 if (self.imageView == nil) { UIImageView tempImageView = alloc/init … self.imageView = tempImageView; [tempImageView release]; } self.imageView.image = self.image; 

和标签一样

如果我理解你的代码,你希望每个“喜欢”,“评论”和“join”的自定义button的单一副本? 然后我认为你添加了太多的自定义button:如果cell = nil,它们会被添加。 UITableView为每个可见行创build一个单元格,所以每个可见行将有多less个副本。

你真的检查过电池是否被正确的重复使用吗? 这就是说,创build的行数只有可视行的数量。

下一步自我getters:answerForCell,navcon和answer.likers:有没有打开的保留?

它可能会进一步下降,但我不能看到tempLabel被释放。 你真的需要告诉我们什么是泄漏。 你应该能够确定它是否是ImageView,标签等