class IdleGC
- IdleGC
- Reference
- Object
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.cridle-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
-
.background_collect : Bool
Calling background_collect requests one background attempt by spinning up a new fiber.
-
.busy(quiet_period : ::Time::Span = self.quiet_period) : Nil
Mark activity without a block.
-
.busy(quiet_period : ::Time::Span = self.quiet_period, &)
Postpone idle collection until the block and its quiet period finish.
-
.collect : Nil
Explicitly force collection now.
-
.collect_if_needed : Bool
Collect if enough memory has been allocated, even if we're busy.
-
.collect_if_needed_and_idle : Bool
Collect if enough memory has been allocated and no tracked work is busy.
-
.last_checked_at : ::Time::Span | Nil
Relative to IdleGC::Time.monotonic, when did IdleGC last check whether or not to run garbage collect?
-
.last_collected_at : ::Time::Span | Nil
Relative to IdleGC::Time.monotonic, when did IdleGC last initiate GC.collect?
-
.last_collected_duration : ::Time::Span | Nil
How long did GC.collect take to run?
-
.min_bytes_since_gc : UInt64
Minimum allocations for conditional collection.
- .min_bytes_since_gc=(v : UInt64) : Nil
-
.quiet_period : ::Time::Span
How long should we wait after work finishes? Defaults to 10 milliseconds.
- .quiet_period=(v : ::Time::Span) : Nil
-
.start : Nil
Start periodic collection.
Class Method Detail
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.
Mark activity without a block. Call again if the work outlasts the period.
Postpone idle collection until the block and its quiet period finish. This is the recommended interface for wrapping application work.
Collect if enough memory has been allocated, even if we're busy.
Collect if enough memory has been allocated and no tracked work is busy.
Relative to IdleGC::Time.monotonic, when did IdleGC last check whether or not to run garbage collect?
Returns nil if we've never checked.
Relative to IdleGC::Time.monotonic, when did IdleGC last initiate GC.collect?
Returns nil if we've never collected.
How long did GC.collect take to run?
Returns nil if we've never collected.
Minimum allocations for conditional collection. Defaults to 1 MiB. Setting this to zero still requires at least one allocated byte.
How long should we wait after work finishes? Defaults to 10 milliseconds.