Re: Are NSViews autoreleased or released?
Re: Are NSViews autoreleased or released?
- Subject: Re: Are NSViews autoreleased or released?
- From: Kaspar Fischer <email@hidden>
- Date: Tue, 6 Dec 2005 18:35:07 +0100
On 06.12.2005, at 03:16, Shawn Erickson wrote:
On 12/5/05, Kaspar Fischer <email@hidden> wrote:
Are NSViews autoreleased or released? For instance, when a
window gets closed, are the window's views and subviews
released or autoreleased?
It doesn't matter since if an object is sent an autorelease message it
will get a release message when the related autorelease pool gets
dealloced (one for each autorelease message sent). Also the use of
release or autorelease is an implementation detail of the framework
that shouldn't be depended on (unless documented otherwise).
I understand that this is an implementation detail in general,
but it seems that I was trapped in one special case were it
seems to matter. Here is the situation:
I have an array of objects, and each object can have an
associated window open. If an object gets removed from
the array, I want its window to be closed. Therefore, I
observe the array and when an element is removed from it,
I close its window.
The problem is that in [windowController close], the window
and its views are not released but autoreleased. As a consequence,
the subviews are *not* deallocated immediately (and observers/
bindings not deregistered immediately). Here, "not immediately"
means "not until the end of the event loop". So when the object
is removed (which happens in the same event loop) it has active
observers, which causes an assertion failure ("An instance
0x6252ec0 of class blabla is being deallocated while key value
observers are still registered with it. Break on
_NSKVODeallocateLog to start debugging.")
In contrast, if the subviews were released immediately, the
observers would be unregistered immediately and the object
could be removed without problems.
(This is related to my post "Undo of insert - how to close
the removed object's window?" But I only realize this now,
for which I apologize. I have just found a solution to this
(and the above problem) and will post it in the other thread.)
Kaspar
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden