Skip to content

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

class method

ObjectSpace.count_symbols

(?::Hash[::Symbol, ::Integer] result_hash) -> ::Hash[::Symbol, ::Integer]
ObjectSpace.count_symbols(result_hash = nil) → hash

Returns a hash containing the number of objects for each Symbol type.

The types of Symbols are the following:

  • mortal_dynamic_symbol: Symbols that are garbage collectable.

  • immortal_dynamic_symbol: Symbols that are objects allocated from the garbage collector, but are not garbage collectable.

  • immortal_static_symbol: Symbols that are not allocated from the garbage collector, and are thus not garbage collectable.

  • immortal_symbol: the sum of immortal_dynamic_symbol and immortal_static_symbol.

If the optional argument result_hash is given, it is overwritten and returned. This is intended to avoid the probe effect.

This method is intended for developers interested in performance and memory usage of Ruby programs. The contents of the returned hash is implementation specific and may change in the future.

This method is only expected to work with C Ruby.