From: Tom Metge Date: 2007-12-27T03:24:54+09:00 Subject: Re: Destroying an Object On Dec 26, 2007, at 10:18 AM, Tim Hunter wrote: > Ken A. wrote: >> Tim Hunter wrote: >>> Ken Awamura wrote: >>>> Suppose I create a new object: >>>> >>>> p = new Object >>>> >>>> How can I kill/destroy this object forever? >>> First, it's >>> >>> p = Object.new >>> >>> Second, you can't. Ruby automatically cleans up an object when >>> there is >>> no more references to it. >> Does ruby's garbage collector really work, or it's as lame as .NET >> garbage collector? > > It really works. > > -- > RMagick: http://rmagick.rubyforge.org/ > > it won't be gc'd until all references to the object are gone... if you want to ensure that it is collected, dereferencing it will guarantee garbage collection: p = nil this isn't as important with instance variables- if wrapped in a method or class, they will be gc'd on the next gc run after the method returns. class and other types are more important... but then again, why use a class variable if you *don't* want it around? and yes, ruby's gc works quite well, more so when you know precisely what to expect :) you can run garbage collection manually, but it almost never works the way you want it to... especially in light of ruby's already trustable gc.