1

UPDATE:

Seems to me like it is pretty much an Apple bug. I tried the following:

  1. create a new single-window project
  2. create a single UIPickerView like the one shown below, only that the picker just allows for turning the dials. That is, neither variables nor any state is manipulated when interacting the picker.

RESULT: No matter whether I use the simple titleForRow:forComponent or viewForRow:forComponent, the picker still leaks 48 bytes each time a dial is turned. Further, I even tried having the picker return views previously allocated in an array set up as a class property in the viewController, so that no views are retained or released but for whatever the picker might do internally after or before it calls the delegate methods. And still, the leaks occur.

Seems like an Apple bug to me.

ORIGINAL QUESTION

I have a textField whose imputView is set to a UIPickerView with 4 components. The picker is used to select a weight / mass which becomes the text in the textField.

Under Instruments, each time I turn a dial / component in the UIPickerView, a leak occurs:

enter image description here Here's the stack trace for the 48 byte leak:

enter image description here

The code through which the UIPickerView gets each component view is:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if(!view)
    {
        view = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 37)] autorelease];
        UILabel *label = (UILabel*)view;
        label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        label.textAlignment = UITextAlignmentCenter;
        label.font = [UIFont boldSystemFontOfSize:24];
        label.backgroundColor = [UIColor clearColor];
    }

    ((UILabel*)view).text = [NSString stringWithFormat:@"%@%i", ((component == 3) ? @"." : @""), row];
    return view;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return  60;
}

And the code that updates the textField to the new textual value is:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSString *newWeight = [NSString stringWithFormat:@"%i%i%i.%i", 
                           [pickerView selectedRowInComponent:0], 
                           [pickerView selectedRowInComponent:1],
                           [pickerView selectedRowInComponent:2],
                           [pickerView selectedRowInComponent:3]];

    self.sampleMassBuffer = [NSDecimalNumber decimalNumberWithString:newWeight];
    weightTextField.text = [[numberFormatter stringFromNumber:self.sampleMassBuffer] stringByAppendingFormat:@" %@", currentConfiguration.weightUnits];
}

I have no idea how the leaks are originating or if they are even mine! Could it be an Apple bug?

SaldaVonSchwartz
  • 3,769
  • 2
  • 41
  • 78
  • Probably not related to your question, but if you're just making a plain label, why not use titleForRow:inComponent: instead of view? – jrturton Mar 20 '12 at 15:59
  • 1
    I don't see any leaks in the code you've posted. – Sam Mar 20 '12 at 16:07
  • 1
    What does `currentConfiguration.weightUnits` look like? Or `sampleMassBuffer`? Have you implemented setters / getters for these properties yourself? The leak could be in there. – jrturton Mar 20 '12 at 16:17
  • currentConfiguration.weightUnits is an NSManagedObject (Core Data) and is owned by a singleton that implements a model / controller bridge. So it's alive throughout the span of the whole app life; it's not even being ever assigned, I'm just calling the getter as you can see. And self.sampleMassBuffer is a retained NSDecimalNumber, and as you can see, I'm doing self.sampleMassBuffer = new_val, so hopefully this translates to 1 - [sampleMassBuffer release], 2 - sampleMassBuffer = nil, 3 - sampleMassBuffer = [new_val retain]. So I don't know that there's a leak there – SaldaVonSchwartz Mar 20 '12 at 18:14
  • currentConfiguration.weightUnits is an NSManagedObject (Core Data)... by that I meant currentConfiguration is a NSManagedobject that persists throughout the application. weightUnits is a property which happens to be an NSString. But still... I'm not changing the property in any way. – SaldaVonSchwartz Mar 20 '12 at 19:53

2 Answers2

0

I'm not sure if this question is answerable any more, except to say that you should file a bug report with Apple using your basic example project.

jrturton
  • 118,105
  • 32
  • 252
  • 268
0

The leak in the SDK. I just confirmed with a trusted source.

SaldaVonSchwartz
  • 3,769
  • 2
  • 41
  • 78