class

IdleGC

Inherits Reference < Object

IdleGC runs garbage collection during quiet periods between application work. Call IdleGC.start, then wrap requests or jobs in IdleGC.busy { ... }.

IdleGC.collect always collects. IdleGC.collect_if_needed checks allocations, and IdleGC.collect_if_needed_and_idle also checks for activity. Use IdleGC.background_collect to request a background attempt.

Constants

DEFAULT_MIN_BYTES_SINCE_GC = 1048576_u64
DEFAULT_QUIET_PERIOD = 10.milliseconds
VERSION = "2.0.0"

Class methods

background_collect

Calling background_collect requests one background attempt by spinning up a new fiber. Returns false if one is already pending. A request near the end of an attempt may be missed; the periodic poll retries.

Source
busy(quiet_period : ::Time::Span = self.quiet_period) : Nil

Mark activity without a block. Call again if the work outlasts the period.

Source
busy(quiet_period : ::Time::Span = self.quiet_period, &)

Postpone idle collection until the block and its quiet period finish. This is the recommended interface for wrapping application work.

Source
collect

Explicitly force collection now.

Source
collect_if_needed

Collect if enough memory has been allocated, even if we're busy.

Source
collect_if_needed_and_idle

Collect if enough memory has been allocated and no tracked work is busy.

Source
last_checked_at

Relative to IdleGC::Time.monotonic, when did IdleGC last check whether or not to run garbage collect?

Returns nil if we've never checked.

Source
last_collected_at

Relative to IdleGC::Time.monotonic, when did IdleGC last initiate GC.collect?

Returns nil if we've never collected.

Source
last_collected_duration

How long did GC.collect take to run?

Returns nil if we've never collected.

Source
min_bytes_since_gc

Minimum allocations for conditional collection. Defaults to 1 MiB. Setting this to zero still requires at least one allocated byte.

Source
min_bytes_since_gc=(v : UInt64) : Nil
Source
quiet_period

How long should we wait after work finishes? Defaults to 10 milliseconds.

Source
quiet_period=(v : ::Time::Span) : Nil
Source
start

Start periodic collection. Calling start again does nothing.

Source

Nested types