iphone - iOS6 UIPickerView 内存泄漏问题。

标签 iphone objective-c memory-leaks xcode4.5 uipickerview

我遇到了内存泄漏:

[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier]; 

NSConcentrateMutableAttributedString.

问题是我没有实现这个委托(delegate)。执行此操作后,现在内存泄漏消失了。这些信息可能对其他人有帮助,因为我花了 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;
}

最佳答案

感谢您的信息。被这个泄漏弄糊涂了。只有很少的评论:

  • 可能 lblRow 应该自动释放:return [lblRow autorelease];

  • [pickerView rowSizeForComponent:component] 可用于获取新标签的大小。

关于iphone - iOS6 UIPickerView 内存泄漏问题。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13045423/

相关文章:

iphone - UIViewController( init 和 initWithNibName )

c++ - 双重删除会发生什么?

iphone - iOS5 中 UIPickerView 选择 RowInComponent 的不同奇怪行为

iphone - 如何将 View Controller 弹出到推送的 View Controller 下方?

objective-c - 将 iOS 版本添加到 Mac 应用程序

iphone - 用于 iPhone 应用程序构建的最佳硬件是什么?

objective-c - iOS 添加目标 :action:forControlEvents only works for one of my button when assigned in for loop

swift - 如何检测内存泄漏 <Allocated Prior To Attach>?

c# - 小操作中的内存泄漏

ios - 即使在 iphone 设备上安装根证书后,Charles 代理也不起作用