Re: NIB's owner doesn't get released because of NSArrayController
Re: NIB's owner doesn't get released because of NSArrayController
- Subject: Re: NIB's owner doesn't get released because of NSArrayController
- From: Keary Suska <email@hidden>
- Date: Thu, 15 Jan 2009 10:42:41 -0700
On Jan 15, 2009, at 10:11 AM, Vitaly Ovchinnikov wrote:
Well, I got the idea and will try this. Just one question: do I miss
something when just releasing my two outlets to two top-level objects.
Your method is more common solution, but am I wrong with mine one? I
have only two objects in my NIB and release them both.
That approach may be OK, but it seems to me to violate "good"
programming practices. Among them: memory management rules, not being
self-documenting, and not being future-proof. Besides, when do you
release the outlets? The file's owner dealloc will never get called,
so you can't do it there. The window controller can't have outlets to
those objects, so...
On Thu, Jan 15, 2009 at 7:40 PM, Keary Suska <email@hidden
> wrote:
On Jan 15, 2009, at 9:04 AM, Vitaly Ovchinnikov wrote:
I'll try to describe it again. I have NIB, NSObject-based owner of
this nib and NSView + NSArrayController in that NIB.
Let's name owner of this NIB MyViewController. It has -init and -
dealloc
methods
Basically, you have a classic retain cycle problem.
-(id) init
{
self = [super init];
[NSBundle loadNibNamed:@"MyView1" owner:self];
This method of loading a nib does not allow you to control top level
objects. Use +loadNibFile:externalNameTable:withZone: or similar.
See the
Resource programming Guide, "Loading Nib Files into Your Program
Programmatically", (locally:
<file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_6.html#//apple_ref/doc/uid/10000051i-CH4-DontLinkElementID_12
>)
for examples.
If you want to keep your current logic, your best bet is to have
the owning
window controller load the nib and manage the NSNibTopLevelObjects
array.
When you release pViewController, release the NSNibTopLevelObjects
array.
Although they won't all release immediately, everything should
release at
the next run loop cycle.
Alternatively, and I think this is a better way to go, don't bind
anything
to file's owner when you are loading nibs in this way. Instead, use
outlets
and/or intermediary controllers. Your sanity will thank you.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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