IOS6 UIPickerView memory leak issue.

I was getting this memory leak:

[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier]; 

and

 NSConcentrateMutableAttributedString. 

The problem was that I did not implement this delegate. After implementing this, memory leaks now disappear. Maybe this information is useful to others, as I spend my 16 hours to figure out this problem.

 // 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 width equal to our picker 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; } 
+6
source share
2 answers

Thanks for your information. This confusion was confused. Just a few comments:

  • Probably lblRow should be implemented: return [lblRow autorelease];

  • [pickerView rowSizeForComponent:component] can be used to get the size for the new label.

0
source

I used IUIPicker in a popover, and every time I rejected a popover, I had a memory leak. I also use ARC, so the easiest way I solved it was by setting UIPickerView = nil to offload. The following seems to have done the trick.

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

All Articles