From: Robert Klemme Date: 2003-12-09T17:27:02+09:00 Subject: Re: WeakRef and Object#hash "Yukihiro Matsumoto" schrieb im Newsbeitrag news:1070956376.605925.8348.nullmailer@picachu.netlab.jp... > Hi, > > In message "Re: WeakRef and Object#hash" > on 03/12/09, Samuel Tesla writes: > > |As best as I can tell, and my understanding may be incorrect. There > |are a total of four references that come in to play in my example > |code: > | > | class WeakRef; end > | wr = WeakRef.new Object.new > | > |1. WeakRef -- a constant that refers to the Class object for WeakRef > |2. Object -- ditto for class Object > |3. wr -- the WeakRef we created > |4. Some reference to an object that may or may not be retained > | somewhere from our call to Object.new > > They are references from Ruby world. GC also scans C stack which is > not supposed to be understood. Is this similar to Java which might also keep a reference to an instance if that is not explicitely cleared *and* the current stack frame is not overwritten? Example: public void foo() { Object x = new Object(); } Now if "foo" is called once and no other methods afterwards, the stack frame keeps intact and the instance is still referenced. What can we do about this in Ruby if we want the instance to be GC'ed? Is there a workaround at least for testing purposes? > It's a some kind of magic. ;-) Uh oh... Here's the original: http://www.sing365.com/music/lyric.nsf/A-Kind-Of-Magic-lyrics-Queen/DC0FC780120693ED482568940001E3CC :-) Cheers robert