From: Garance A Drosehn Date: 2005-07-05T06:09:41+09:00 Subject: Re: What's the correspond method of PERL's DESTROY in ruby On 6/17/05, Yi Zhang 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