[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

What's the correspond method of PERL's DESTROY in ruby

Yi Zhang

6/17/2005 9:59:00 PM

Hello



What's the corresponding method of PERL's DESTROY in ruby?



Thanks,

Yi Zhang

4 Answers

Tim Hunter

6/17/2005 10:24:00 PM

0

Yi Zhang wrote:
> What's the corresponding method of PERL's DESTROY in ruby?

Generally speaking there is no equivalent. Like Perl, Ruby's garbage
collection cleans up unreferenced objects without any intervention. If
you want do something to clean up an external resource at the point when
you're finished using the instance, the cooresponding Ruby idiom is to
use a block. Check out http://www.rubygarden.org/ruby?....

Florian Groß

6/18/2005 1:06:00 AM

0

Garance A Drosehn

7/4/2005 9:10:00 PM

0

On 6/17/05, Yi Zhang <yzhang@frontbridge.com> wrote:
>
> What's the corresponding method of PERL's DESTROY in ruby?
>
I am not aware of any direct equivalent to DESTROY, but there are
some tricks you can use in perl which *might* make the automatic
garbage collection work better for you.

If you have a ruby object which includes some large arrays or
hashes in the object, then you might want to call the 'clear'
method on each of those arrays when you're done with the object.
And after sending the 'clear', you could set the variable-name
to nil. I have used this in a few scripts, and it has helped to
reduce the memory requirements of the script.

So, for some of the classes I create, I have a 'clear' method,
and that does something like:

def clear
@array1.clear
@array1 = nil
@hashtab.clear
@hashtab = nil
end

That doesn't really destroy the object, but it makes it easier for
ruby to do some of it's garbage-collection. In some situations this
has made a significant difference for me. In other situations, it
doesn't seem to make any noticeable difference.

--
Garance Alistair Drosehn = drosihn@gmail.com
Senior Systems Programmer or gad@FreeBSD.org
Rensselaer Polytechnic Institute; Troy, NY; USA


Gene Tani

7/5/2005 2:16:00 AM

0