Quick answer: Use Allocator.TempJob for NativeArrays passed into jobs (lifetime up to 4 frames). Use Allocator.Persistent for long-lived buffers. Never Allocator.Temp for job inputs — it’s main-thread one-frame.
Console: “Allocator.Temp passed to a job. The job may use it after it has been deallocated.” Switch to TempJob.
The Symptom
Warning or error in Editor when scheduling jobs that consume NativeArrays. May not crash immediately but undefined behavior on worker threads.
The Three Allocators
- Temp: main-thread, one-frame. Fastest. For local short-lived buffers within a single function.
- TempJob: up to 4 frames, jobs allowed. For job inputs/outputs.
- Persistent: live forever. Manual Dispose required.
The Fix
var data = new NativeArray<float>(1024, Allocator.TempJob); // not Temp
var job = new MyJob { data = data };
var handle = job.Schedule();
handle.Complete();
data.Dispose(); // before 4 frames pass
For data living longer than 4 frames, use Persistent and Dispose at the right teardown point (OnDestroy, system shutdown).
Loops Across Frames
If you collect data over multiple frames and process it later, Persistent is correct:
NativeList<float3> _accumulated = new(Allocator.Persistent);
void OnDestroy() { _accumulated.Dispose(); }
Verifying
Editor warnings disappear after switching. Memory profiler shows allocations going to TempJob/Persistent appropriately. Burst doesn’t care about allocator choice; only the safety system does.
“TempJob for jobs. Persistent for long-lived. Dispose. No warning.”
Related Issues
For data race, see data race. For Deallocate errors, see deallocate.
Right allocator. Right lifetime. Warnings gone.