Game dev
Saved & recent

Garbage collection

Also called: GC

Related terms: allocation, hitch

In languages such as C# and JavaScript, memory that is no longer used is reclaimed automatically by a garbage collector. When it runs, the game may freeze for several milliseconds. The player feels a hitch.

The fix is to create less garbage during play: reuse objects with an object pool and avoid making temporary objects every frame.

Further reading
Unity: Garbage collection best practices
0 1 2 3 4 5 6 7 0 20 40 60 80 heap usage (MiB) collection frame duration time (s)
In this example, allocations raise heap usage between collections. At 2, 4 and 6 seconds, each collection reclaims memory and coincides with a longer frame.

View in the full Game dev collection