At 15:43 -0600 27/2/09, James Cicenia wrote:
Here is my code:

- (void)monthFruitAction:(id)sender{

MonthPickerViewController *mpvc = [[MonthPickerViewController alloc]initWithNibName:@"MonthPicker" bundle:nil];
        [mpvc setMyParentController:self];
        mpvc.view.frame =CGRectMake(19,66,260,258);
        [fruitTypeView addSubview:mpvc.view];
}

How should I release mpvc ?

Conceptually, who owns the view?

Or alternatively, who controls when the view will be released?

Basically, you want the controller to be released when the view is released.

Usually in this sort of case I would have some overriding controller (probably the window controller) that controlled adding/removing the subview and that would also handle the controller. What object is monthFruitAction: in? If it is the window controller, then it could store the MonthPickerViewController in a property, and whenever time comes to remove the view, it would also release (nil the property) the MonthPickerViewController.

Another option would be to override viewDidMoveToSuperview (or on the iPhone didMoveToSuperview) in the view, check for the superview being nil and if so release the controller. Technically, someone else might still have a reference to the view, and add it back to another superview later, but thats an unusual design.

I'm not sure if the controller has a weak enough reference to the view that you could release the controller in the view's dealloc method.

Enjoy,
   Peter.

--
     Run macros from your iPhone with Keyboard Maestro Control!
       or take a break with Aragom Space War for your iPhone

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
Aragom Space War <http://www.stairways.com/iphone/aragom> Don't get killed!
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to