Internal: JobTempAlloc has allocations that are more than 4 frames old

I’m at a loss with an issue I’m having with the job system at the moment. I wrote a really nice couple of jobs but every now and even though I don’t have any JobTemp allocations I get the, “Internal: JobTempAlloc has allocations that are more than 4 frames old” warning.

However I’m not using any temp allocators. I only use 2:

  • _revealerDataList which is declared as NativeList(Allocator.Persistent);
  • I also use Texture2D.GetRawTextureData() which I thought would be the issue but I ruled it out after I changed to use a cached NativeArray(size, Allocator.Persistent) which didn’t help.
        private void RunJob()
        {
            _jobHandle = new JobHandle();

            // _revealerDataList = new NativeList<RevealerData>(Allocator.Persistent);
            _revealerDataList.Clear();

            foreach (var revealer in _revealers)
                _revealerDataList.Add(new RevealerData(revealer.VisionRage, revealer.Position, revealer.Faction));
     
            foreach (FactionData faction in _factions)
            {
                // Thought this might be issue, but I changed to a cached
                // NativeArray<Color32>(size, Allocator.Persistent) which didn't help
                var dataBuffer = faction.MapDataTexture.GetRawTextureData<Color32>();

                var resetFactionJob = new ResetFactionJob
                {
                    DataBuffer = dataBuffer,
                    CoverSpeed = _settings.CoverSpeed,
                    RevealOpacities = _settings.RevealOpacities,
                    RevealSpeed = _settings.RevealSpeed,
                    Time = Time.deltaTime
                }.Schedule(dataBuffer.Length, 256);

                var calculateVisionJob = new CalculateVisionJob
                {
                    DataBuffer = dataBuffer,
                    Size = _settings.Size,
                    Revealer = _revealerDataList,
                    Offset = _fullOffset,
                    Scale = _settings.Scale,
                    Faction = faction.Faction

                }.Schedule(_revealerDataList.Length, 64, resetFactionJob);

                _jobHandle = JobHandle.CombineDependencies(_jobHandle, calculateVisionJob);
            }
        }

Now I think the issue is I’m trying to do this job over multiple frames as it’s costly. On my machine at the moment it takes on average takes 3 frames (when I’m running at 250fps) but occasionally takes 4-5 which is when the warnings popup.

        void ITickable.Tick()
        {
            if (_settings.ForceUpdateEveryFrame || _jobHandle.IsCompleted)
            {
                _jobHandle.Complete();

                // Do work on main thread

                RunJob();
            }
        }

Are multi frame jobs just not supported? I intentionally avoided any temp allocators so I thought it’d be fine. I might just have to change back to using my own workers.

I think anything lasting more than 4 frames should be set to use Allocator.Permanent and then Dispose() them when you’re done after more than 4 frames.

Maybe that’s the intention for this? I don’t know. Correct me if I’m wrong.

“Permanent” not exists in Allocator enum.

  • Allocator.Temp has the fastest allocation. It is intended for allocations with a lifespan of 1 frame or fewer and is not thread-safe. Temp NativeContainer allocations should call the Dispose method before you return from the function call.
  • Allocator.TempJob is a slower allocation than Temp, but is faster than Persistent. It is intended for allocations with a lifespan of 4 frames or fewer and is thread-safe. Most short jobs use this NativeContainer allocation type.
  • Allocator.Persistent is the slowest allocation, but lasts throughout the application lifetime. It is a wrapper for a direct call to malloc. Longer jobs may use this NativeContainer allocation type.

https://docs.unity3d.com/2018.1/Documentation/ScriptReference/Unity.Collections.Allocator.Persistent.html

You mean Allocator.Persistent.

That’s the thing though. I’m not using any TempJob allocators and yet I’m still getting the warning. I’m not sure if I’m locking an internal unity job out by taking multiple frames or something else is up.

1 Like

The same issue here. Can’t understand in which moment it appear and how to disable it