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

-(id) init
{
    self = [super init];
    [NSBundle loadNibNamed:@"MyView1" owner:self];
    return self;
}

- (void) dealloc
{
    // next two lines added after your comment
    [pView release];
    [pArrayController release];

    [super dealloc];
}

In the main window controller I do the following:

- (void) windowDidLoad
{
     pViewController = [[MyViewController alloc] init];
     pCustomView = [pViewController view]; // I will use this view on
the main window
}

- (void) dealloc
{
    [pViewController release]; // this should call -dealloc method of
MyViewController, but it doesn't
    // if I call [pViewController retainCount] here, it returns "1"
    [super dealloc];
}

Hope, you got the idea of the code.
Array controller is bound to file's owner in NIB, so it holds
reference to it and -release doesn't call -dealloc that should release
array controller that holds a reference... etc....
If I remove binding in NIB file, MyViewController's -dealloc is called
after -release. I added method to MyViewController that breaks binding
and call this method before releasing MyViewController. This helps,
but I think there is a better way to do this.


On Thu, Jan 15, 2009 at 5:44 PM, Jason Foreman <ja...@threeve.org> wrote:
> On Wed, Jan 14, 2009 at 11:58 PM, Vitaly Ovchinnikov
> <vitaly.ovchinni...@gmail.com> wrote:
>> Well, OK. I am ready to release all root objects myself. Just tested
>> with subclassed NSView from that NIB - it didn't get released
>> automatically.
>> So I added several -release calls to -dealloc method of my NIB's owner
>> and now it will release everything.
>> But the problem is still there: -dealloc of my view controller didn't
>> get called because array controller still retains it!
>> As I wrote above, I added special "killer" method that breaks binding
>> and after calling it I can call -release and it will call NIB owner's
>> -dealloc. But this is ugly...
>
> It's not clear to me from this response, so just to double check:  do
> you -release the array controller when you -release the view?  The
> array controller is also a top-level object in your nib, so it needs
> to be released.  This will have a similar effect to you calling
> -unbind..., but is more correct.  What you are doing with -unbind is
> likely leaking NSArrayController instances, so while your NSView will
> have its -dealloc called, the array controller will not.
>
>
> Jason
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/vitaly.ovchinnikov%40gmail.com
>
> This email sent to vitaly.ovchinni...@gmail.com
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to