【发布时间】:2011-12-30 03:09:27
【问题描述】:
看到下面的代码,它只是一个方法,我无法理解其中的内存管理问题,请告诉我,下面的代码发生了什么,为什么?
-(IBAction)selectMarina {
NSLog(@"Select Marina");
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
//[pickerView release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
//[closeButton release];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[pickerView selectRow:0 inComponent:0 animated:NO];
}
这里是Potential leak of object allocated on line 112 and stored into close button
它正在在线显示这样的消息
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
如何在这段代码中进行适当的内存管理,您能否详细指定它
谢谢
【问题讨论】: