我得到了这个内存泄漏:
[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier];
和
NSConcentrateMutableAttributedString.
问题是我没有实现这个委托。实现这一点后,内存泄漏就消失了。可能这些信息对其他人有用,因为我只花了16个小时来解决这个问题。
// Do something with the selected row.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
// Get the text of the row.
NSString *rowItem = [NSString stringWithFormat:@" %@",[machineData objectAtIndex:row]];
// Create and init a new UILabel.
// We must set our label's width equal to our picker's width.
// We'll give the default height in each row.
UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f)];
// Make the text color red.
[lblRow setTextColor: [UIColor blackColor]];
[lblRow setFont:[UIFont boldSystemFontOfSize:20]];
// Center the text.
[lblRow setTextAlignment:UITextAlignmentLeft];
// Add the text.
[lblRow setText:rowItem];
// Clear the background color to avoid problems with the display.
[lblRow setBackgroundColor:[UIColor clearColor]];
// Return the label.
return lblRow;
}
答案 0 :(得分:0)
感谢您的信息。对此漏洞感到困惑。只有少数评论:
可能应该自动释放lblRow:return [lblRow autorelease];
[pickerView rowSizeForComponent:component]
可用于获取新标签的大小。
答案 1 :(得分:0)
我在弹出窗口中使用了IUIPicker,每次我解开popover时都会出现内存泄漏。我也在使用ARC,所以我解决这个问题的最简单方法是在卸载时设置UIPickerView = nil。以下似乎已经成功了。
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.pickerView = nil;
}