WeakRegistry>>finalizeValues & WeakKeyDictionary

Igor Stasenko siguctua at gmail.com
Thu Jul 26 22:07:52 UTC 2007


I found few questionable places in WeakRegistry/WeakKeyDictionary
which want to discuss with list.

a WeakRegistry uses associationsDo:  to determine which keys are GCed,
and to collect values needed to send #finalize.

There are at least two things to object:
- why WeakRegistry shows up the keys = nil in associationsDo:, while
in #keys, #keysDo: it just skips over them, indicating that there no
associations with nil keys? This breaks the behavior consistency IMHO.

- if you carefully check the WeakRegistry>>finalizeValues method,
you'll see that dictionary will be scanned twice (first time in
associationsDo:, second time in valueDictionary>>finalizeValues: ).
Its scanned once only in case if there's no keys=nil and no values
needed to be finalized.

For both issues above, i think its better to add a method into
WeakKeyDictionary , lets say
#collectNilKeyValues , which will do good things for WeakRegistry by
cleaning itself from nil keys and at same time return a collection of
values needed to be finalized.

And then, there will be no need to show up keys = nil in
#associationsDo: and WeakKeyDictionary will behave as if there no
keys=nil for any request outside.

I'm also wonder, why WeakRegistry uses WeakKeyDictionary instead of
WeakIdentityKeyDictionary.

Just consider example:

WeakRegistry default add: myObject executor: myExecutor.
WeakRegistry default add: myObject copy executor: myCopyExecutor.
(suppose myObject = myObject copy return true , and myObject hash =
myObject copy hash too)

I din't tested it, but i think that in result you'll get
myCopyExecutor>>finalize sent when myObject will be GCed, but not its
copy.

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list