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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With