delete_at – does it actually remove from RAM

I’ve been looking for ways to manually delete objects in ruby, and I’ve come across the idea of doing a = [] a[0] = a.delete_at(0)
This deletes it from the array and allows no way of gettin to it, but I was wondering if it really deletes the object from memory?

If not, could I use the garbage collector to do so?

delete_at removes the reference from the array but the object will not be removed from memory until the garbage collector removes it. You can start a garbage collection by calling GC#start. I’m not sure what guarantees there are about any particular object being freed on any particular collection.

It is unfortunately not possible to mark an object as being ready for garbage collection in MRI.

However, as @kofno says, you can start the garbage collector with GC.start. You can also get stats about the garbage collector with GC.stats.

Okay, thanks for the information — I think I know how I could make a little game that works how I’d like. :slight_smile: