Quick answer: Unity Job System throwing “allocator must be TempJob or Persistent”? The NativeArray you flagged [DeallocateOnJobCompletion] was allocated with Allocator.Temp.
A job schedules with a NativeArray flagged for auto-dispose; Unity errors at validation. Allocator.Temp has a 4-frame lifetime — jobs may outlive it.
Temp Is Frame-Local
Allocator.Temp data is invalidated 4 frames after allocation. Jobs may run later — auto-dispose by a job is forbidden because the array could already be invalid.
Use TempJob
var data = new NativeArray<int>(100, Allocator.TempJob);TempJob is the sweet spot — the job will dispose it on completion (or within a frame). Faster than Persistent for short-lived data.
Persistent for Long-Lived
If the array crosses frames, use Allocator.Persistent and dispose manually in OnDestroy. Auto-dispose by job is still allowed.
Dispose Order
If a job reads two arrays and only one is auto-disposed, dispose the other manually in OnDestroy. Mismatched dispose is a leak source.
Verifying
The job runs without validation errors. Memory profiler shows no leaks across spawn/destroy cycles.
“DeallocateOnJobCompletion needs TempJob or Persistent. Temp is frame-local.”
Pick TempJob as the default and only switch to Persistent when you measure cross-frame need — saves recurring “why is this not disposed” trips.