2009/10/27 Igor Stasenko <siguctua@gmail.com>:
2009/10/26 Schwab,Wilhelm K <bschwab@anest.ufl.edu>:
Philippe, Stef,
That's fine for Seaside, but what about other users of weak collections? Â I think I have found the weakness (pun intended) in Squeak/Pharo: weaklings do only half of what they should do. Â They (correctly) do not prevent garbage collection of the objects they reference, but they apparently fail to clean up after these objects have been finalized.
In Dolphin, the following returns an empty array:
| map | map := WeakLookupTable new         at:2 put:String new;         yourself. MemoryManager current collectGarbage. map keys asArray.
Pharo is content to answer nil from #at:put: but still keep the key:
| map | map := WeakValueDictionary new         at:2 put:String new;         yourself. 5 timesRepeat:[ Smalltalk garbageCollect. ]. map keys asArray.
and why the key should go away? I think that this is an implementation nuance, but not bug or missing feature. No-one would expect from dictionary keys to automatically mutate depending on the state of the associated values. If you want such behavior, why not implement own WeakLookupTable ?
suppose, one may want to know, what values became garbage, to do additional _custom_ processing. While its currently possible using WeakValueDictionary , it will be problematic using WeakLookupTable , because you wont know what values are gone. -- Best regards, Igor Stasenko AKA sig.