Skip to content

Commit e1a896a

Browse files
committed
[DOC] Improve docs for ObjectSpace.reachable_objects_from
1 parent e9e4647 commit e1a896a

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

ext/objspace/objspace.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -557,42 +557,37 @@ collect_values(st_data_t key, st_data_t value, st_data_t data)
557557
* call-seq:
558558
* ObjectSpace.reachable_objects_from(obj) -> array or nil
559559
*
560-
* [MRI specific feature] Return all reachable objects from `obj'.
560+
* Returns all reachable objects from +obj+ as an array:
561561
*
562-
* This method returns all reachable objects from `obj'.
562+
* ObjectSpace.reachable_objects_from(['a', 'b', 'c'])
563+
* #=> [Array, 'a', 'b', 'c']
563564
*
564-
* If `obj' has two or more references to the same object `x', then returned
565-
* array only includes one `x' object.
565+
* The returned array is deduplicated, meaning that if +obj+ refers
566+
* to another object more than once, it will only be added to the array
567+
* once:
566568
*
567-
* If `obj' is a non-markable (non-heap management) object such as true,
568-
* false, nil, symbols and Fixnums (and Flonum) then it simply returns nil.
569+
* ObjectSpace.reachable_objects_from([v = 'a', v, v])
570+
* #=> [Array, 'a']
569571
*
570-
* If `obj' has references to an internal object, then it returns instances of
571-
* ObjectSpace::InternalObjectWrapper class. This object contains a reference
572-
* to an internal object and you can check the type of internal object with
573-
* `type' method.
572+
* Returns +nil+ if +obj+ is not a markable object (i.e. non-heap
573+
* managed) object. Non-markable objects include +true+, +false+,
574+
* +nil+, certain symbols, small integers, and floats:
574575
*
575-
* If `obj' is instance of ObjectSpace::InternalObjectWrapper class, then this
576-
* method returns all reachable object from an internal object, which is
577-
* pointed by `obj'.
576+
* ObjectSpace.reachable_objects_from(1)
577+
* #=> nil
578578
*
579-
* With this method, you can find memory leaks.
579+
* All references to internal objects in the returned array are wrapped
580+
* using ObjectSpace::InternalObjectWrapper objects. This object contains
581+
* a reference to the internal object and the type of the object can
582+
* be accessed using the ObjectSpace::InternalObjectWrapper#type method.
580583
*
581-
* This method is only expected to work with C Ruby.
582-
*
583-
* Example:
584-
* ObjectSpace.reachable_objects_from(['a', 'b', 'c'])
585-
* #=> [Array, 'a', 'b', 'c']
586-
*
587-
* ObjectSpace.reachable_objects_from(['a', 'a', 'a'])
588-
* #=> [Array, 'a', 'a', 'a'] # all 'a' strings have different object id
584+
* If +obj+ is instance of ObjectSpace::InternalObjectWrapper, then this
585+
* method returns all reachable object from the internal object.
589586
*
590-
* ObjectSpace.reachable_objects_from([v = 'a', v, v])
591-
* #=> [Array, 'a']
592-
*
593-
* ObjectSpace.reachable_objects_from(1)
594-
* #=> nil # 1 is not markable (heap managed) object
587+
* This method is useful for debugging purposes, such as finding
588+
* memory leaks.
595589
*
590+
* This method is only expected to work with C Ruby.
596591
*/
597592

598593
static VALUE

0 commit comments

Comments
 (0)