On Mar 24, 2010, at 6:50 PM, Yoandy RodrÃguez MartÃnez wrote:
Hello again:
I need to create an object's registry that keeps certain objects in a dictionary and a second registry that keeps only objects currently in the first registry so i thought it was a good idea to user IdentityDictionary and WeakIdentityKeyDictionary so when the any object in the first registry is removed then the second registry remove's it too. Problem is that when i try to test my code, the second assertion fails. Is there anything wrong with my test or weak collections are not suppose to work like that?
Yes. But doesn't your method hold on to the object, too? It's pointed to by the "object" temp, which is not weak.
ColonyTest>>testWeakRefs |registry anotherRegistry object | registry:= Registry uniqueInstance. "this keeps weak references" anotherRegistry := Colony new. object:= ColonyMember new. registry register: anotherRegistry. anotherRegistry addMember: object. registry register: object. "object is into the second registry" self assert:[ anotherRegistry contains: object]. "if we unregister this reference then the registry should lose it too" registry unregister: object. self deny:[ anotherRegistry contains: object]
-- Marcus Denker -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team RMoD.