Re: How to completely release every object allocated when opening a NIB file ?
Re: How to completely release every object allocated when opening a NIB file ?
- Subject: Re: How to completely release every object allocated when opening a NIB file ?
- From: mmalcolm crawford <email@hidden>
- Date: Tue, 13 Jan 2004 21:15:03 -0800
On Jan 13, 2004, at 8:12 PM, Charles Srstka wrote:
Which brings me to the point, isn't this badly broken? The point of
Cocoa's reference counting was that you were supposed to only have to
release something if you specifically called init or retain on it. As
it is, the rule has to be extended to: "You only need to release
something if you called init or retain on it. Except for top-level
objects in nib files, which you own and have to release, even though
you didn't call retain or init, even though your code might not even
*know* about those objects, and even though the nib file could be
edited after you write the code and your code could have to deal with
objects that didn't *exist* at the time the code was written. Oh, and
forget this rule for NSDocument's nib file, which *will* release the
objects, causing you to crash if you try to release them. So don't
release those! But do release everything in everything other nib file.
Wait, unless you use a NSWindowController, because *it* will release
the nib file objects... but oh, Cocoa's memory management is easy!"
I think you're being overly dramatic. The situation can be explained
much more simply. Let's start with the documentation:
"When you load a nib file, all its top level objects have a reference
count of one. When the objects are no longer needed, another object
needs to release them. That other object is usually the files owner.
Note that NSWindowController automatically releases its nib files
objects for you. Also, NSWindow has a isReleasedOnClose attribute,
which automatically releases the window for you when its closed."
<file:///Developer/Documentation/Cocoa/Conceptual/MemoryMgmt/index.html>
Most applications that most beginners create will have either a single
window, or be document-based. In these cases, memory management is
basically taken care of automatically. Document-based applications
take care of objects in the nib file automatically; we don't care about
objects in the single-window case since they persist for the lifetime
of the application, and go when the app terminates.
In other words, no memory management issues.
For slightly more complex situations: multiple window controllers, or
loadable panels, inspectors etc. Window controllers deal with memory
management; inspectors last for the lifetime of the application, so you
don't have to worry about them.
Again, no memory management issues.
For other more complex situations: If your nib file is controlled by a
window controller, as is recommended, it takes care of memory
management for you. And for other configurations, recall, "NSWindow
has a isReleasedOnClose attribute, which automatically releases the
window for you when its closed."
So things typically have to become reasonably complicated before you
generally have to worry about memory management issues, and these are
unlikely to be situations to confront a newcomer.
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.