← Back to Nakama · project planning pack

Skill · Version 1.0.0

Unity memory and garbage collection

Tracks Unity memory growth across scenes, assets and object lifetimes. Distinguishes temporary managed allocations from retained resources so fixes address the actual owner of the memory.

unity-game-memory-gc

Agents using this skill

See how it helps

When is it useful?

Use it when repeated levels, pools or asynchronous work retain objects and memory does not settle back to expected levels.

What does it help you do?

  • Separates managed allocations from native and asset ownership.
  • Compares snapshots at equivalent scene lifecycle points.
  • Bounds pools and traces retained references, events and async work.

Try asking this

Investigate a Unity game that uses more memory after every dungeon visit. Capture comparable snapshots before entry and after leaving, then inspect retained textures, event listeners and pooled enemies. Apply a focused lifetime fix and repeat several visits; verify stable retained memory without introducing frequent allocation spikes during combat.

Detailed documentation

Read the skill’s original instructions, examples and checks in their authored language.

Details…Show less

Memory Lifetime and Garbage Collection

Record Unity version, scripting backend, target memory budget and a representative load/play/unload sequence. Distinguish managed heap, native objects, texture/mesh/audio residency and reserved versus committed/resident memory.

  • Attribute allocation sites and collection spikes; GC.Alloc sample duration is not the full later collection cost. Avoid treating every allocation outside a hot path as a defect.
  • Compare memory snapshots at equivalent lifecycle points and inspect retainers/ownership. Repeated scene loads or pooled reuse should return to a justified steady state.
  • Keep pools bounded and reset references, callbacks and async work. Pooling can reduce churn while retaining too much memory; measure both effects.
  • Release resources through the APIs of their actual ownership system: Unity objects, NativeContainers, Addressables handles and external buffers have different contracts.
  • Investigate event subscriptions, static collections, async continuations and domain-reload-disabled state before forcing collections or unloading assets globally.
  • Use supported Memory Profiler and allocation tools and label Editor/player differences. Preserve serialized and gameplay state while changing lifetime.

Check repeated open/close, scene unload, death/respawn, pool growth and cancellation under representative load. Report bytes, ownership evidence and actual target conditions.

Reference: Unity memory management, using the installed Editor version.

Included files 2

  • LICENSE.txt
  • SKILL.md