• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NIB's owner doesn't get released because of NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NIB's owner doesn't get released because of NSArrayController


  • Subject: Re: NIB's owner doesn't get released because of NSArrayController
  • From: "Vitaly Ovchinnikov" <email@hidden>
  • Date: Thu, 15 Jan 2009 19:04:52 +0300

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 <email@hidden> wrote:
> On Wed, Jan 14, 2009 at 11:58 PM, Vitaly Ovchinnikov
> <email@hidden> 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 (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
>
_______________________________________________

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

  • Follow-Ups:
    • Re: NIB's owner doesn't get released because of NSArrayController
      • From: Keary Suska <email@hidden>
    • Re: NIB's owner doesn't get released because of NSArrayController
      • From: "Jason Foreman" <email@hidden>
References: 
 >NIB's owner doesn't get released because of NSArrayController (From: "Vitaly Ovchinnikov" <email@hidden>)
 >Re: NIB's owner doesn't get released because of NSArrayController (From: "Jason Foreman" <email@hidden>)
 >Re: NIB's owner doesn't get released because of NSArrayController (From: "Vitaly Ovchinnikov" <email@hidden>)
 >Re: NIB's owner doesn't get released because of NSArrayController (From: "Jason Foreman" <email@hidden>)

  • Prev by Date: save screengrab on iphone
  • Next by Date: Re: save screengrab on iphone
  • Previous by thread: Re: NIB's owner doesn't get released because of NSArrayController
  • Next by thread: Re: NIB's owner doesn't get released because of NSArrayController
  • Index(es):
    • Date
    • Thread