From: ts Date: 2003-12-09T19:17:39+09:00 Subject: Re: WeakRef and Object#hash >>>>> "R" == Robert Klemme writes: R> What can we do about this in Ruby if we want the instance to be GC'ed? Is R> there a workaround at least for testing purposes? Like has said matz, nothing. But there is something worst, be carefull with weakref : the example was given in ruby-core. Someone created weakrefs and stored the ID of the reference in a hash and when he wanted to retrieve the object he called _id2ref. His algorithm was : * _id2ref raise an error ==> this mean that the object was recycled * otherwise it retrieve the original object. Except that one day he has a big surprise, because ruby has recycled one his object and *re-use* the same reference for one of its internal object. When he called _id2ref, ruby has returned the internal object and it dont really liked to find it, latter, in a ruby variable. This is why _id2ref was modified (i.e. it can't return internal object) to protect ruby if someone else use this wrong algorithm. Because the algorithm is still wrong. Just imagine : * you create a weakref from an Array and store the ID * ruby recycle the Array and re-use the same reference for an Hash * you call _id2ref, ruby return the new Hash and not the original Array Guy Decoux