Re: Proper Way to "Unload" a Loaded Nib w/Bindings [Solved, Maybe]
Re: Proper Way to "Unload" a Loaded Nib w/Bindings [Solved, Maybe]
- Subject: Re: Proper Way to "Unload" a Loaded Nib w/Bindings [Solved, Maybe]
- From: "Shawn Erickson" <email@hidden>
- Date: Tue, 27 Mar 2007 15:58:14 -0700
On 3/27/07, Keary Suska <email@hidden> wrote:
on 3/27/07 2:00 PM, email@hidden purportedly said:
>> The problem is that when I release the top level objects, my app crashes. My
>> research seems to show that this is because of an NSWindow's
>> initialFirstResponder outlet being set.
>
> My guess is that you are either overreleasing an object, or you have a weak
> reference an object that has already been released.
>
> But this isn't a nib problem. This is standard Cocoa memory management and
> you'd have the same problem wether the objects were created from a nib or
> programmatically.
The problem was not what I originally thought, but was because I was using
NSWindow's -makeFirstResponder. If I call it with nil before I release the
top level objects, the crash stops. This would indicate an issue with the
nib, from my point of view, and a bug to boot. The nib/window should be
responsible for the first responder, since it is a subview, and one that I
am neither creating nor releasing (always an NSTextField in the window).
Fortunately, using -makeFirstResponder was just a hold-over from a previous
implementation that I don't need to use, so I abandoned its use completely
and have remained crash-free.
>> The docs warn that all outlets
>> should be set to nil for all objects in the nib, but don't mention how this
>> may be done when the outlets aren't known by the nib owner.
>
> Again, this is responsibility of the individual objects, not really the nib's
> owner. A window that is being released should not be using its initial first
> responder. If it is, something's wrong -- but this should have nothing to do
> with the fact the objects were created by a nib.
I should have been more specific--I was referring to the Resource
Programming Guide, which states:
"After releasing the top-level objects, it is a good idea to clear any
outlets pointing to objects in the nib file by setting them to nil. You
should clear outlets associated with all of the nib fileĀ¹s objects, not just
the top-level objects."
My first assumption was that it meant in-nib outlets, but a closer reading
could indicate that they mean programmatically-created outlets to nib
objects from outside of the nib itself.
"programmatically-created outlets"?
All it is saying is that once you release the top-level objects of a
nib any IBOutlets you have in the nibs owner are no longer valid since
the objects they reference in theory no longer exist. So setting those
to nil can prevent attempts to use now stale pointers. Additionally if
you have setters for your outlets that retain what they get passed
then you will need to make sure to use the setter to set them to nil
(trigger the retained object to be released).
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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