Quick answer: handle.Complete() before array.Dispose(). Or array.Dispose(handle) to defer disposal until the job finishes.
You schedule a parallel job, then dispose the input array. Unity throws because the safety check sees the job still has a read handle on the buffer.
The Symptom
InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it in editor. In production with safety checks off, undefined behavior.
The Fix
var data = new NativeArray<float>(1024, Allocator.TempJob);
var job = new MyJob { Data = data };
var handle = job.Schedule();
// Bad — immediate dispose while job runs
// data.Dispose();
// Good — complete first
handle.Complete();
data.Dispose();
// Or deferred via overload
// data.Dispose(handle); // dispose after job done
The Dispose(JobHandle) overload chains a deallocation job after the producer. Useful when you can’t block the main thread immediately.
Verifying
Run with Burst Safety Checks On in editor. No exception. Switch to Allocator.Persistent if leaks: leak detection points to source line.
“Complete the handle. Then dispose. Or chain dispose to handle.”
Related Issues
For Burst determinism, see determinism. For Jobs batch size, see batch size.
Complete first. Then dispose.