GC.config
# File tmp/rubies/ruby-4.0.0/gc.rb, line 444
def self.config hash = nil
if Primitive.cexpr!("RBOOL(RB_TYPE_P(hash, T_HASH))")
if hash.include?(:implementation)
raise ArgumentError, 'Attempting to set read-only key "Implementation"'
end
Primitive.gc_config_set hash
elsif hash != nil
raise ArgumentError
end
Primitive.gc_config_get
end
This method is implementation-specific to CRuby.
Sets or gets information about the current GC configuration.
Configuration parameters are GC implementation-specific and may change without notice.
With no argument given, returns a hash containing the configuration:
GC.config # => {rgengc_allow_full_mark: true, implementation: "default"}
With argument hash_to_merge given, merges that hash into the stored configuration hash; ignores unknown hash keys; returns the configuration hash:
GC.config(rgengc_allow_full_mark: false) # => {rgengc_allow_full_mark: false, implementation: "default"} GC.config(foo: 'bar') # => {rgengc_allow_full_mark: false, implementation: "default"}
All-Implementations Configuration
The single read-only entry for all implementations is:
-
:implementation: the string name of the implementation; for the Ruby default implementation,'default'.
Implementation-Specific Configuration
A GC implementation maintains its own implementation-specific configuration.
For Ruby’s default implementation the single entry is:
-
:rgengc_allow_full_mark: Controls whether the GC is allowed to run a full mark (young & old objects):-
true(default): GC interleaves major and minor collections. A flag is set to notifyGCthat a full mark has been requested. This flag is accessible viaGC.latest_gc_info(:need_major_by). -
false: GC does not initiate a full marking cycle unless explicitly directed by user code; seeGC.start. Setting this parameter tofalsedisables young-to-old promotion. For performance reasons, we recommended warming up the application usingProcess.warmupbefore setting this parameter tofalse.
-
Ruby version changes
-
3.4
-
GC.configadded to allow setting configuration variables on the Garbage Collector. [Feature #20443]
-