• 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: Keary Suska <email@hidden>
  • Date: Thu, 15 Jan 2009 09:40:43 -0700


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.

HTH,

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


  • Follow-Ups:
    • 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: "Vitaly Ovchinnikov" <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>)
 >Re: NIB's owner doesn't get released because of NSArrayController (From: "Vitaly Ovchinnikov" <email@hidden>)

  • Prev by Date: Re: NIB's owner doesn't get released because of NSArrayController
  • 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