On Thu, Jan 15, 2009 at 10:04 AM, Vitaly Ovchinnikov <vitaly.ovchinni...@gmail.com> wrote: > - (void) dealloc > { > // next two lines added after your comment > [pView release]; > [pArrayController release]; > > [super dealloc]; > }
This won't work as you intend, see below for explanation. > > 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]; > } You are seeing the correct results here. The array controller is still holding a reference to your view controller, so it will not be deallocated at this time. > > 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. After your nib is loaded, your MyViewController will be retained both by the window controller and the array controller that is bound to it. Also remember that -dealloc is not called until the retain count is zero. So your view controller cannot possibly be deallocated while the array controller holds a reference to it. You need to release the array controller somewhere other than the view controller's -dealloc method. You can choose to do this wherever is appropriate for your application. One possibility might be the window controller's -close method. Or you can do it in whatever method you are unbinding the array controller, as you've done already. Just make sure that you do release the array controller so as not to leak it. 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com