ObjectSpace
The ObjectSpace module contains a number of routines that interact with the garbage collection facility and allow you to traverse all living objects with an iterator.
ObjectSpace also provides support for object finalizers. These are procs that will be called when a specific object is about to be destroyed by garbage collection. Typically, you either call ObjectSpace methods as module methods as in ObjectSpace.count_objects or you include ObjectSpace as a module in another class and call the methods directly.
This is just a glance at what ObjectSpace can do; there’s more in the official documentation.
The method ObjectSpace.define_finalizer(object, proc = proc()) adds proc as a finalizer, called automatically when object is about ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access