0
請參閱下面的代碼,它只是一個方法,我無法理解其中的內存管理問題,請告訴我,下面的代碼中發生了什麼,以及爲什麼?如何使用產品>在XCode中分析來釋放對象?
-(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]];
我怎樣才能做到在這段代碼正確的內存管理,並且可以指定它在細節
謝謝
爲什麼我會釋放pickerView? –
它是全球性的,也不是本地的,那麼你如何說釋放它? –
我想念那一點。如果實例是全局聲明的,則必須在dealloc方法中釋放。 – iamsult