Skip to content

Commit 1d3e2bd

Browse files
committed
[DOC] Improve docs for ObjectSpace.reachable_objects_from_root
1 parent f0d45e0 commit 1d3e2bd

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

ext/objspace/objspace.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,30 @@ collect_values_of_values(VALUE category, VALUE category_objects, VALUE categorie
665665
* call-seq:
666666
* ObjectSpace.reachable_objects_from_root -> hash
667667
*
668-
* [MRI specific feature] Return all reachable objects from root.
668+
* Returns a hash of objects directly reachable from the VM roots,
669+
* grouped by the root that reaches them.
670+
*
671+
* The roots are the entry points the garbage collector starts from when it
672+
* marks live objects, such as the virtual machine and the global variable
673+
* table. The keys of the returned hash are strings naming each root, and each
674+
* value is an array of the objects reachable from that root:
675+
*
676+
* require 'objspace'
677+
*
678+
* reachable = ObjectSpace.reachable_objects_from_root
679+
* reachable.keys # => ["vm", "global_tbl", "machine_context", "global_symbols"]
680+
* reachable.values.first # => [#<Ractor:#1 running>, ...]
681+
*
682+
* The returned hash compares its keys by identity, so it cannot be indexed
683+
* with a string literal; iterate over it (or over its #values) instead.
684+
*
685+
* Any reference to an internal object is wrapped in an
686+
* ObjectSpace::InternalObjectWrapper object.
687+
*
688+
* This method is useful for debugging the object graph, for example when
689+
* tracking down the cause of a memory leak.
690+
*
691+
* This method is only expected to work with C Ruby.
669692
*/
670693
static VALUE
671694
reachable_objects_from_root(VALUE self)

0 commit comments

Comments
 (0)