Post
The runtime helpfully cleans up your unused memory -- at the worst possible moment, causing a visible stutter.
Garbage collection (GC) is the automatic memory management system in languages like C#, Java, and Lua that periodically identifies and frees memory that is no longer referenced. In business software, GC pauses are invisible. In games running at 60fps, a 16ms GC pause means a dropped frame -- and players notice. Unity developers are intimately familiar with this problem because C# uses a generational garbage collector that can pause the main thread when it runs. The mitigation strategies are well-established: object pooling to avoid allocations, pre-allocating collections to their maximum expected size, using structs instead of classes where possible, caching references instead of creating temporary objects, and minimizing string operations. Incremental garbage collectors spread the work across multiple frames but add complexity. This is one reason AAA engines often use C++ -- manual memory management means zero GC surprises.
Example
Unity's old Boehm garbage collector was notorious for causing frame rate hitches in mobile games. A common horror story was a game running smoothly at 60fps until the GC kicked in every few seconds, causing visible stutters. Unity eventually introduced an incremental GC option that spreads collection across multiple frames, reducing the severity of individual pauses.
Why it matters
Garbage collection pauses are the most common source of mysterious frame rate hitches in games built with managed languages. Understanding how and when the GC runs, and structuring code to minimize allocations during gameplay, is essential knowledge for any developer working in Unity, Java-based engines, or any other GC environment.
Related concepts