On 28/02/2009, at 9:42 AM, James Cicenia wrote:

The question is where do I release that object.

The general answer is, when you no longer need it. So, when is that?


If I put the release at the end of the method, nothing will pop into my view. If I don't release it, it works fine, but then I am worried about a leak.

- (void)monthFruitAction:(id)sender{

MonthPickerViewController *mpvc = [[MonthPickerViewController alloc]initWithNibName:@"MonthPicker" bundle:nil]; <<==== If I autorelase, this method will NOT show my view.
        [mpvc setMyParentController:self];
        mpvc.view.frame =CGRectMake(19,66,260,258);
        [fruitTypeView addSubview:mpvc.view];
[mpvc release] <<==== If I put this in, this method will NOT show my view.
}

So, I am wondering how I am to release this object.


Without having a better grasp of your overall design, it's difficult to say. But it looks to me as if what you're doing here is creating a controller in response to some user action - a menu perhaps? - which handles some sort of view. Is this a modal or sheet dialog? Maybe not, as you are adding the controller's view as a subview to something else. Presumably the controller needs to stick around as long as the view otherwise there's nothing to control that view. If the view can get removed at some stage then it seems that would be the right time to also release its controller, since you no longer need it.

But beyond that, who knows?

There are aspects of this that appear to be playing a bit fast and loose with MVC, but again it's hard to say for sure.

--Graham


_______________________________________________

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