WeakKeyDictionary - does this code look right??

Gerardo Richarte gera at core-sdi.com
Wed Mar 3 15:23:29 UTC 1999


Peter Smet wrote:

> Anyway, when I test the idea, the objects in the WeakKey
> Dictionary never seem to get garbage collected, even
>
> What am I doing wrong? I am puzzled by the class comment in
> WeakKeyDictionary which states:

    I don't know what's wrong. It should work, but it may take some time,
as there would be a garbageCollection for weak values to be released.
    What WeakKeyDictionary class Comment says about registering its
instances, is:

    a _ WeakKeyDictionary new.
    WeakArray addWeakDependent: a.
    a at: Object new put: 70.
    Smalltalk garbageCollect.
    a

    print this expression, you should get an empty WeakKeyDictionary. If
you comment out the line starting with 'WeakArray', and you print it,
you'll get a WeakKeyDictionary with (nil->70). If you register a weak
instance, when any of its values is released (becouse it's no longer
referenced by anybody), it gets sent #finalizeValues. (Take a look at
WeakKeyDictionary | #finalizeValues, WeakArray | #finalizationProcess and
WeakArray | #addWeakDependent:)

    Referenced Bye!
    Richie++





More information about the Squeak-dev mailing list