Re: Garbage collection and about windows
Re: Garbage collection and about windows
- Subject: Re: Garbage collection and about windows
- From: Matt Neuburg <email@hidden>
- Date: Wed, 11 Nov 2009 16:37:18 -0800
- Thread-topic: Garbage collection and about windows
On Wed, 11 Nov 2009 18:16:11 -0500, Ben Haller
<email@hidden> said:
> This policy seems to imply that windows can live on their own,
>without a reference to them from the outside world (because the window
>list references them), but panels cannot; a panel has to be strong-
>referenced by somebody. Somebody has to *own* it. I don't really see
>the logic there.
The memory management policy on Mac OS X (and iPhone) *is* an
ownership-based policy, so seeing the logic isn't really important. The rule
is simple: If you yourself did not alloc or copy an instance, then that
instance is a candidate for deallocation; retain it or risk losing it. That
simplicity is good.
I doubt that mere membership in the window list causes a window to be
retained. Probably something else is doing it. For example, it might be the
nib-loading memory-management rules, or the existence of an
NSWindowController that has taken ownership of the window.
A revealing and important document in this regard is:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Loadin
gResources/CocoaNibs/CocoaNibs.html
See esp. under Nib Object Retention. The difference between Mac OS X and
iPhone memory management policy is striking, and has made a big difference
in my life. After "mysteriously" losing the object at the far end of an
IBOutlet because I failed to retain it, on iPhone, I now retain *all* my
outlets, even on Mac OS X (where this kind of thing doesn't happen if you're
not using garbage collection). Like chicken soup, it can't hurt; and
declared properties (with a "retain" policy) make it easy to do correctly.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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