[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Garbage Collection
From: |
Richard Frith-Macdonald |
Subject: |
Re: Garbage Collection |
Date: |
Wed, 25 May 2011 15:55:52 +0100 |
On 25 May 2011, at 12:47, David Chisnall wrote:
> There were also some limitations with the GNUstep approach - aside from
> needing programmer effort, which somehow defeats the point of GC. The lack
> of weak references meant that some common patterns caused memory leaks. For
> example, in the traditional retain/release world, an object registers itself
> with NSNotificationCenter, which holds an unretained pointer to it, and then
> unregisters itself in -dealloc, when it is no longer referenced by anything
> else. In a garbage collected world, NSNotificationCenter has a reference to
> the object, so it will never be freed, so can not unregister itself. The
> notification center requires a weak reference, so that the object can be
> freed when nothing else holds a reference to it and the notification centre
> can then clean up.
Er ... the GNUstep implementation has always had weak references and didn't
need more programmer effort ... it just does it a bit differently from the way
Apple later chose. GNUstep registers weak references for a class at runtime
when the class is initialised, while Apple implemented it in the compiler, so
the difference in programmer effort is basically whether the programmer calls a
function in +initialize or declares a variable as 'weak' in a header.