Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

GC.count

() -> ::Integer
self.count → integer

Returns the total number of times garbage collection has occurred:

With the default GC, counts the current Ractor’s collections.

Example
GC.count # => 385
GC.start
GC.count # => 386

Ruby version changes

  1. 4.1
    • GC.stat accepts scope: :ractor (the default), scope: :local (a synonym for :ractor), and scope: :global. With the default collector, the global scope reports cumulative collection counts and measured marking/sweeping CPU time across Ractors, including history from destroyed object spaces, without requesting a stop-the-world snapshot. Unscoped GC.stat, GC.count, and GC.total_time retain their current-Ractor behavior.

See also .config .disable .compact .enable also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0