我该什么时候发布这个对象?

时间:2010-10-08 03:42:36

标签: cocoa-touch

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

    CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15);
    UIImageView *label = [[UIImageView alloc] initWithFrame:imageFrame];

    if (row == 0)
    {
        label.backgroundColor = [UIColor redColor];
    }
    if (row == 1)
    {
        label.backgroundColor = [UIColor blueColor];
    }
    if (row == 2)
    {
        label.backgroundColor = [UIColor blackColor];
    }   
    return label;
}

标签是泄漏。我知道。但....

1 个答案:

答案 0 :(得分:2)

在返回

之前做[label autorelease];