Re: how to release my window controller
Re: how to release my window controller
- Subject: Re: how to release my window controller
- From: "Michael Ash" <email@hidden>
- Date: Sat, 2 Aug 2008 17:44:45 -0400
On Sat, Aug 2, 2008 at 12:50 PM, Torsten Curdt <email@hidden> wrote:
>> How many of these are you creating, one?
>
> In this very case just one. In fact I am trying to replace what was a modal
> dialog before now with non-modal window. So the AppController would need to
> make sure there is only one instance. But this raised the general question
> how to deal with this best.
>
>> No matter what, the best way is to keep a reference in a master
>> controller.
>
> That's what I thought.
>
>> - If it's just a single window, make an ivar to hold on to the
>> controller. You don't even need to release it, since you can just
>> reuse it.
>
> That's what I got working atm. But re-using the window does have
> implications on initialization. (It would have to get a reset method or
> something)
Keep in mind that making the computer do something many times is
generally no more difficult than making it do something once. I'd
suggest removing the reset method and having just a general "set"
method that you use each time, including the first time.
>> If you really want to, then have the window controller
>> notify you when the window closes, then you can destroy it.
>
> Oh ...right that's option 4 ....but that feels a like a little more work
> than just calling a selector
It is, but it's also cleaner.
>> If you're not using garbage collection, you can play some tricks, like
>> having the window controller retain itself, or having the app
>> controller release the sender of the window-closed callback without
>> actually keeping track of anything. But generally these only *appear*
>> to save time, they don't actually help, so I don't recommend it.
>
> You mean in windowWillClose: ?
Probably the didClose one. If you retain yourself in init (so that
your owner can do a balanced alloc/init/release) then you can release
yourself in windowDidClose:, and if you plan to keep a reference in
the app controller, then you can set up a notification or delegate
callback that you'll send from windowDidClose: so that the controller
can release it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden