Quick answer: Garbage collection stutter comes from the runtime pausing your game to reclaim memory, triggered by frequent allocations. The cause is allocating too much per frame, forcing GC pauses that block the frame. Reducing allocations reduces it.
Garbage collection stutter, periodic hitches caused by the memory system, is a common performance problem in managed languages and engines. It has a specific, addressable cause. Here's what causes garbage collection stutter.
How GC Causes Stutter
In managed environments, the garbage collector periodically reclaims memory no longer in use, and doing so often pauses your game briefly, causing a hitch. What triggers frequent, stutter-causing GC is allocation.
- Frequent allocations, allocating lots of memory (creating 'garbage') triggers GC more often
- Per-frame allocations, allocating in code that runs every frame, generating constant garbage
- Temporary objects, creating short-lived objects that immediately become garbage
- Hidden allocations, allocations from operations you don't realize allocate (some library calls, string operations, boxing)
- Large heap, a big managed heap taking longer to collect, causing bigger pauses
The more garbage you create (through allocations), the more often the GC runs, and each run can pause the game, producing the stutter.
Why It's Often Hidden
GC stutter can be hard to trace because the allocations causing it may be hidden, in library calls, string operations, or boxing you don't realize allocate. And the stutter appears as frame-time spikes that you have to look for, since average FPS hides them.
Bugnet's performance snapshots capture frame-time spikes from real sessions, so the hitches GC causes surface in your data. Capturing the spikes is the first step to recognizing GC stutter, which then points at reducing allocations.
Reducing GC Stutter
Reducing GC stutter means reducing allocations, especially per-frame: avoid allocating in hot paths, reuse objects (pooling) instead of creating and discarding them, avoid hidden allocations (string concatenation, boxing) in frequent code, and minimize garbage generation. Fewer allocations mean less frequent GC and less stutter.
Bugnet captures the frame-time spikes GC causes, so you can confirm the stutter and verify reductions. So garbage collection stutter comes from frequent allocations triggering GC pauses, and reducing it means cutting allocations, especially per-frame, through reuse and avoiding hidden garbage.
GC stutter comes from frequent allocations triggering garbage-collection pauses that block the frame. The cause is allocating too much, especially per-frame. Reduce allocations through reuse and avoiding hidden garbage to reduce it.