views:

200

answers:

2

Hi,

I was wondering if there is a similar .finalize() method for Ruby objects, that marks them ready for garbage collection. If I would create 20,000 objects and each instance has a counter, I would like the object to be marked for garbage collection when reaches zero. I know this is pretty much a Java approach, but I have not sufficient experience with Ruby under-the-hood to understand how this could be done better.

Thank you for your answers, comments and feedback!

+1  A: 

As far as I know, you can't mark an object ready for GC but you can force GC at any time:

GC.start

If the item can be freed, it will be freed.

Evgeny Shadchnev
+2  A: 

_why wrote an awesome article on GC in Ruby called "The Fully Upturned Bin" which luckily got saved when he decided to disappear from the Internet:

http://viewsourcecode.org/why/hacking/theFullyUpturnedBin.html

Michael Kohl
Thanks for the link, will start reading right away!
Shyam