Skip to content

Commit 00a3b71

Browse files
committed
[DOC] Improve docs for ObjectSpace.memsize_of_all
1 parent 81e06e7 commit 00a3b71

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

ext/objspace/objspace.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,24 @@ each_object_with_flags(each_obj_with_flags cb, void *ctx)
108108

109109
/*
110110
* call-seq:
111-
* ObjectSpace.memsize_of_all([klass]) -> Integer
111+
* ObjectSpace.memsize_of_all(klass = nil) -> integer
112112
*
113-
* Return consuming memory size of all living objects in bytes.
113+
* Returns the total memory size of all living objects in bytes.
114114
*
115-
* If +klass+ (should be Class object) is given, return the total memory size
116-
* of instances of the given class.
115+
* ObjectSpace.memsize_of_all # => 12502001
117116
*
118-
* Note that the returned size is incomplete. You need to deal with this
119-
* information as only a *HINT*. Especially, the size of +T_DATA+ may not be
120-
* correct.
121-
*
122-
* Note that this method does *NOT* return total malloc'ed memory size.
117+
* If +klass+ is given (which must be a Class or Module), returns the total
118+
* memory size of objects whose class is, or is a subclass, of +klass+.
123119
*
124-
* This method can be defined by the following Ruby code:
120+
* class MyClass; end
121+
* ObjectSpace.memsize_of_all(MyClass) # => 0
122+
* o = MyClass.new
123+
* ObjectSpace.memsize_of_all(MyClass) # => 40
125124
*
126-
* def memsize_of_all klass = false
127-
* total = 0
128-
* ObjectSpace.each_object{|e|
129-
* total += ObjectSpace.memsize_of(e) if klass == false || e.kind_of?(klass)
130-
* }
131-
* total
132-
* end
125+
* Note that the value returned may be an underestimate of the actual amount
126+
* of memory used. Therefore, the value returned should only be used as a hint,
127+
* rather than a source of truth. In particular, the size of +T_DATA+ objects may
128+
* not be correct.
133129
*
134130
* This method is only expected to work with C Ruby.
135131
*/

0 commit comments

Comments
 (0)