iOS6 UIPickerView内存泄漏问题。 [英] iOS6 UIPickerView memory leak issue.

查看:220
本文介绍了iOS6 UIPickerView内存泄漏问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这个内存泄漏:

I was getting this memory leak:

[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier]; 

NSConcentrateMutableAttributedString.

问题是我没有实现此委托。实现这一点后,内存泄漏就消失了。可能这些信息对其他人有用,因为我只花了16个小时来解决这个问题。

Issue was that I had not implemented this delegate. After implementing this now memory leaks goes away. May be this information helpful for other as I spend mine 16 hours only to figure out this issue.

// 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;
}


推荐答案

我在弹出窗口中使用了IUIPicker每当我解开popover时,我都有内存泄漏。我也在使用ARC,所以我解决这个问题的最简单方法是在卸载时设置UIPickerView = nil。以下似乎已经成功了。

I used IUIPicker in a popover and every time I dismissed the popover I had memory leak. I am also using ARC, so the easiest way I resolved this was by setting the UIPickerView = nil on unload. The following appears to have done the trick.

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.pickerView = nil;
}

这篇关于iOS6 UIPickerView内存泄漏问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆