Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: Mark an object for garbage collection

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!

like image 605
Shyam Avatar asked Apr 15 '10 10:04

Shyam


1 Answers

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.

like image 122
Evgeny Shadchnev Avatar answered Oct 13 '22 00:10

Evgeny Shadchnev