wave7-idisposable-managed-component

Release native IDisposable resources from managed IComponentData before entity removal.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents native memory leaks when a managed IComponentData instance owns unmanaged or native resources that must be explicitly released before the component is removed or its entity is destroyed.

Core Features & Use Cases

  • Safe native resource cleanup: Ensures NativeArray/NativeList and other IDisposable native holders are disposed at the correct lifecycle boundary (component removal or entity destruction).
  • Correct ECS cleanup flow: Provides a canonical approach using a PendingDestroy tag and a cleanup system that calls Dispose and then destroys the entity via an ECB.
  • Anti-pattern guidance: Avoids relying on GC for IDisposable, avoids missing explicit Dispose calls, and warns against calling Dispose inside jobs.

Quick Start

Ask the AI to generate a NativeDataComponent cleanup plan using an ECS PendingDestroy tag and a cleanup SystemBase that disposes the component’s native resources before destroying the entity.

Frequently Asked Questions about wave7-idisposable-managed-component

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

FAQPage Schema
How do I dispose of NativeArray inside a managed IComponentData when an entity is destroyed in Unity DOTS?

To dispose of NativeArray inside managed IComponentData, use a cleanup system with a PendingDestroy tag to explicitly call Dispose before destroying the entity via an EntityCommandBuffer. This prevents native memory leaks during structural changes.

Why does my Unity ECS leak memory when removing components that hold NativeList fields?

Memory leaks occur because garbage collection does not handle native IDisposable resources like NativeList. You must explicitly dispose of these unmanaged holders in a dedicated cleanup system before the component or entity is structurally removed.

What is the best way to prevent double-free errors when disposing native resources in Unity ECS?

The best way to prevent double-free errors is to guard disposal calls with IsCreated checks. This verifies the native resource exists before releasing it, ensuring safe cleanup of IDisposable fields during entity destruction.

Can I call Dispose on NativeArray from inside a Unity job thread?

No, you should not call Dispose on native resources from inside a job thread. Dispose native IDisposable resources deterministically on the main thread within a cleanup system to avoid job-thread disposal issues and ensure safe removal.

When do I need a cleanup system for managed IComponentData in Unity DOTS?

You need a cleanup system when a managed IComponentData owns unmanaged or native IDisposable resources that require explicit release. It ensures deterministic lifecycle handling by freeing memory before structural changes or entity destruction.