secret
Created

  • Download Gist
riobjspace.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
$ ri --no-pager ObjectSpace
ObjectSpace
 
(from ruby core)
------------------------------------------------------------------------------
 
The objspace library
 
The objspace library extends the ObjectSpace module and adds several methods
to get internal statistic information about object/memory management.
 
You need to require 'objspace' to use this extension module.
 
Generally, you *SHOULD NOT* use this library if you do not know about the MRI
implementation. Mainly, this library is for (memory) profiler developers and
MRI developers who need to know about MRI memory usage.
 
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, procs that will be
called when a specific object is about to be destroyed by garbage collection.
 
a = "A"
b = "B"
 
ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
ObjectSpace.define_finalizer(b, proc {|id| puts "Finalizer two on #{id}" })
 
produces:
 
Finalizer two on 537763470
Finalizer one on 537763480
------------------------------------------------------------------------------
Class methods:
 
_id2ref
allocation_class_path
allocation_generation
allocation_method_id
allocation_sourcefile
allocation_sourceline
count_nodes
count_objects
count_objects_size
count_tdata_objects
define_finalizer
each_object
garbage_collect
memsize_of
memsize_of_all
reachable_objects_from
trace_object_allocations
undefine_finalizer

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.