Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
GC.latest_gc_info
(?::Hash[::Symbol, untyped]? hash) -> ::Hash[::Symbol, untyped]
(::Symbol key) -> untyped
GC.latest_gc_info → new_hash
GC.latest_gc_info(key) → value
GC.latest_gc_info(hash) → hash
gc.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/gc.rb, line 590
def self.latest_gc_info hash_or_key = nil
if hash_or_key == nil
hash_or_key = {}
elsif Primitive.cexpr!("RBOOL(!SYMBOL_P(hash_or_key) && !RB_TYPE_P(hash_or_key, T_HASH))")
raise TypeError, "non-hash or symbol given"
end
Primitive.cstmt! %{
return rb_gc_latest_gc_info(hash_or_key);
}
end
With no argument given, returns information about the most recent garbage collection:
Example
GC.latest_gc_info # => {major_by: :force, need_major_by: nil, gc_by: :method, have_finalizer: false, immediate_sweep: true, state: :none, weak_references_count: 0, retained_weak_references_count: 0}
With symbol argument key given, returns the value for that key:
Example
GC.latest_gc_info(:gc_by) # => :newobj
With hash argument hash given, returns that hash with GC information merged into its content; this form may be useful in minimizing probe effects:
Example
h = {foo: 0, bar: 1} GC.latest_gc_info(h) # => {foo: 0, bar: 1, major_by: nil, need_major_by: nil, gc_by: :newobj, have_finalizer: false, immediate_sweep: false, state: :sweeping, weak_references_count: 0, retained_weak_references_count: 0}
Ruby version changes
-
3.2
-
Expose
need_major_gcviaGC.latest_gc_info. GH-6791
-
See also
.latest_compact_info
.malloc_allocated_size
.enable
.malloc_allocations
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0