68 · Performance · 2D and 3D

GC spikes

Garbage collection pauses that cause hitches.

In C#, JavaScript and other garbage-collected languages, every new object or string adds garbage. Eventually the collector pauses to clean up, and a 10 ms pause in the middle of a fight is a visible hitch. Avoiding allocations in per-frame code keeps the frame graph flat.

←↑↓→ or WASD moveG allocate / reuseD-pad to dodge

Try this: Dodge the falling slimes. Watch the garbage bar: when it fills, the game freezes for a moment and the slimes jump. Switch to Reuse buffers and the freezes stop.

Freezes 0Hits 0

When the garbage bar fills, the collector freezes the game for a moment and slimes jump forward.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

Remove per-frame allocations: profile allocations in Update, reuse lists, buffers and strings instead of creating them, use non-allocating physics queries and pooled objects, cache components, and keep combat frames free of collections longer than 0.005 s, even when the frame rate is high.

43 words · one sentence to paste as is

Where it's used

Common mistakes

Creating new lists, strings and closures every frame, updating UI text every frame, allocating physics queries, ignoring the allocation column in the profiler, and assuming the GC is free because the average fps is fine.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.