[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Weak references & GC
From: |
Richard Frith-Macdonald |
Subject: |
Re: Weak references & GC |
Date: |
Wed, 19 Feb 2003 10:21:51 +0000 |
On Wednesday, February 19, 2003, at 06:19 am, James Knight wrote:
Hi, I recently have been hit with some crashing bugs in my app that
uses gnustep with GC, and traced it back to the fact that
NSNotificationCenter uses disguised pointers so that the GC doesn't
keep the referenced objects around. However, when the object
disappears, the observation is not cleared. In non-GC mode it's
clearly the user's responsibility to clear the observation in the
-dealloc method. However, in GC mode, I feel the system should be
doing this for you. The following patch accomplishes this, and does
not affect non-GC mode at all.
I kind of assumed that objects registering themselves as observers
would use the gcFinalize method to remove themselves as observers when
they are garbage collected... like the removal in the dealloc method
where GC is not used.
While I'm sympathetic to the idea that the system might automatically
remove observer when they are deallocated, this would be a difference
between the GC and non-GC methods of operation (which might lead to a
little confusion), and more importantly, it would be
inconsistent/confusing if the notification system did this but other
classes using weak references didn't.
So ... if we intend to have automatic removal of observers from
notification centers when operating with GC, we should also do the same
for any other occurrences of weak references ...