[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Destroying an Object
From:       Tom Metge <tom () accident-prone ! com>
Date:       2007-12-26 18:24:54
Message-ID: 216FD3C0-545F-4108-ABED-DA6243B83350 () accident-prone ! com
[Download RAW message or body]


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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic