memory-safety

Audits Unity DOTS/Hybrid code for memory-lifetime and GC-avoidance violations.

6|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/dyCuong03/unity-agent-team --skill memory-safety
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: memory-safety
Source: https://github.com/dyCuong03/unity-agent-team/tree/main/.claude/skills/memory-safety
Command: npx skills add https://github.com/dyCuong03/unity-agent-team --skill memory-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents native container lifetime bugs and managed allocation “GC bombs” in Unity DOTS/Hybrid code paths, reducing editor exceptions and hard-to-debug memory leaks.

Core Features & Use Cases

  • Allocator lifetime correctness: Ensures Allocator.Persistent allocations always have matching Dispose() in the proper lifecycle hook (OnDestroy / state.Dispose-bound fields).
  • Job-safe container usage: Enforces rules around passing NativeArray between main thread and jobs, resizing patterns, and correct usage of parallel writers.
  • GC-avoidance in hot paths: Flags managed allocation anti-patterns in OnUpdate (string interpolation/formatting, LINQ, boxing, dictionary writes) and provides DOTS-native replacements.
  • Blob asset best practices: Guides read-only long-lived data via BlobAssetReference<T> built once and never mutated.

Quick Start

Use the memory-safety skill to audit your Unity DOTS/Hybrid system for Allocator.Persistent leaks and hot-path GC allocations before you ask for verifier-level performance and safety checks.

Frequently Asked Questions about memory-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Unity DOTS memory leaks from Allocator.Persistent native containers?▼

Fix Unity DOTS memory leaks by mapping allocation lifetime to the correct allocator type and ensuring lifecycle-matched Dispose() calls in OnDestroy or state-bound fields. This prevents native container leaks caused by missing cleanup hooks.

Why does my Unity DOTS OnUpdate cause GC spikes and managed allocation errors?▼

Unity DOTS OnUpdate causes GC spikes due to managed allocation anti-patterns like string interpolation, LINQ, and boxing. Eliminate these hot-path regressions by replacing them with DOTS-native data structures and parallel writers.

How do I safely pass NativeArray between main thread and parallel jobs in Unity DOTS?▼

Safely pass NativeArray between threads in Unity DOTS by enforcing job-safety constraints for parallel execution and data ownership. Use parallel writers and correct resizing patterns to prevent race conditions and memory corruption.

When should I use BlobAssetReference instead of NativeContainers for persistent data in Unity?▼

Use BlobAssetReference for read-only, long-lived persistent data in Unity instead of NativeContainers. Build blob assets once and never mutate them to safely manage static data outside the garbage collector without risking memory leaks.

Can I use this memory-safety approach for Hybrid DOTS workflows or only pure DOTS?▼

You can apply this memory-safety approach to both DOTS and Hybrid workflows. It enforces allocator choice, GC-avoidance rules, and lifecycle-matched Dispose guarantees across any jobified system managing native containers and disposables.