Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
GC.stat_heap
# File tmp/rubies/ruby-3.3.0/gc.rb, line 252
def self.stat_heap heap_name = nil, hash_or_key = nil
Primitive.gc_stat_heap heap_name, hash_or_key
end
Returns information for heaps in the GC.
If the first optional argument, heap_name, is passed in and not nil, it returns a Hash containing information about the particular heap. Otherwise, it will return a Hash with heap names as keys and a Hash containing information about the heap as values.
If the second optional argument, hash_or_key, is given as Hash, it will be overwritten and returned. This is intended to avoid the probe effect.
If both optional arguments are passed in and the second optional argument is a symbol, it will return a Numeric of the value for the particular heap.
On CRuby, heap_name is of the type Integer but may be of type String on other implementations.
The contents of the hash are implementation specific and may change in the future without notice.
If the optional argument, hash, is given, it is overwritten and returned.
This method is only expected to work on CRuby.
The hash includes the following keys about the internal information in the GC:
- slot_size
-
The slot size of the heap in bytes.
- heap_allocatable_pages
-
The number of pages that can be allocated without triggering a new garbage collection cycle.
- heap_eden_pages
-
The number of pages in the eden heap.
- heap_eden_slots
-
The total number of slots in all of the pages in the eden heap.
- heap_tomb_pages
-
The number of pages in the tomb heap. The tomb heap only contains pages that do not have any live objects.
- heap_tomb_slots
-
The total number of slots in all of the pages in the tomb heap.
- total_allocated_pages
-
The total number of pages that have been allocated in the heap.
- total_freed_pages
-
The total number of pages that have been freed and released back to the system in the heap.
- force_major_gc_count
-
The number of times major garbage collection cycles this heap has forced to start due to running out of free slots.
- force_incremental_marking_finish_count
-
The number of times this heap has forced incremental marking to complete due to running out of pooled slots.