class IdleGC

Overview

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.

Defined in:

idle-gc.cr
idle-gc/request.cr
idle-gc/time.cr
idle-gc/timer.cr

Constant Summary

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

Class Method Summary

Class Method Detail

def self.background_collect : Bool #

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.


[View source]
def self.busy(quiet_period : ::Time::Span = self.quiet_period) : Nil #

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


[View source]
def self.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.


[View source]
def self.collect : Nil #

Explicitly force collection now.


[View source]
def self.collect_if_needed : Bool #

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


[View source]
def self.collect_if_needed_and_idle : Bool #

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


[View source]
def self.last_checked_at : ::Time::Span | Nil #

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

Returns nil if we've never checked.


[View source]
def self.last_collected_at : ::Time::Span | Nil #

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

Returns nil if we've never collected.


[View source]
def self.last_collected_duration : ::Time::Span | Nil #

How long did GC.collect take to run?

Returns nil if we've never collected.


[View source]
def self.min_bytes_since_gc : UInt64 #

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


[View source]
def self.min_bytes_since_gc=(v : UInt64) : Nil #

[View source]
def self.quiet_period : ::Time::Span #

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


[View source]
def self.quiet_period=(v : ::Time::Span) : Nil #

[View source]
def self.start : Nil #

Start periodic collection. Calling start again does nothing.


[View source]