- Home /
How do I fix "JobTempAlloc has allocations that are more than 4 frames old" when I'm not actually using Allocator.TempJob?
In my DOTS project, I am getting this error:
Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
whenever I run my DOTS based scripts. The project is an editor tool so I am running it in the editor.
I am not using Allocator.TempJob
anywhere in the scripts that cause this error. I'm only using Allocator.Persistent
and then disposing those arrays after all the jobs complete and using Allocator.Temp
for arrays allocated and disposed of within jobs. I already tried changing all the Allocator.Temp
's to Persistents
and that didn't help. I am scheduling Jobs
with dependencies to each other and then checking for when they complete every frame using EditorApplication.update
. This way they run in the background and don't halt the main thread. When the work is relatively small, I don't get the error, but when I give the tool a bigger task to complete I get this error message.
I also noticed that when I schedule the jobs and then immediately call jobHandle.Complete() I get no warning no matter how large the jobs are. The warning only comes when I call schedule and then check jobHandle.IsCompleted every frame and then call jobHandle.Complete() when that returns true.
I am using UnsafeList in these jobs as well. I am doing so so that I can have arrays of arrays in jobs. I do this by using NativeArray>.
Does Unity perhaps create jobs behind the scenes that use TempJob
allocators in order to schedule jobs or copy NativeArrays
or combine JobHandles
or anything like that? If so then I could try to identify what's too big for Unity's behind the scenes job and split it up into smaller chunks.
I can try to create a project with the error reproducible if anyone wants to take a look. I am using Unity 2019.4.10f1 for this project.
Answer by andrew-lukasik · Feb 01, 2021 at 02:11 PM
Does this warning message details specific line where allocation happened?
Yes - Case solved, pretty much. Just fix the code it points to (i.e. make sure this allocation is released).
No - My bet is on packages in use or their dependencies. This is not about workload per se but what specific code it triggers; animation? - look into animation packages, rendering - look into rendering packages, yyy??? - look into core dots packages, it well may be their fault in some cases.
Sidenote:
Do not change the Allocator
type to Persistent
everywhere. It will hide allocation problems instead of fixing them. Use it only when this specific data piece is really a persistent one i.e. is intendent to exist for very long time.
It does not give any indication of where the allocation is happening. I do think it has something to do with work load. The specific scripts involved take in a number of arguments when they are called to do work. When I give small numbers as arguments, the jobs complete quickly and I get no warnings. But when I give bigger numbers the jobs take longer and I get the warnings. I only get the warnings when I give those bigger numbers.
I agree that using persistent can hide allocation problems, but I cannot use Allocator.TempJob as my jobs take hundreds of frames to complete and TempJob only works for jobs that take 4 or less frames. This is all taking place in the editor, not in play mode, so perhaps that might be influencing things.
Not sure what "bigger numbers" means exactly but you may want to make sure you're not allocating crazy amount of memory as a result and/or tripping over some hard-coded system/world limits (those exist and time just well may be one of those, idk). Because even non-consequential SetName
is restricted to some amount (thousands) of calls after which it starts to throw exceptions.
I say “bigger numbers” because I’m trying not to bring in the actual algorithms used so I can just keep it simple for now. I’m still in the process of trying to whittle down the code to find the cause of the warning. I think you might be on to something regarding not allocating too much memory and I think it might be the time dimension that’s the problem. I wonder if the content in this article https://www.jacksondunstan.com/articles/5472 might be related to my problem. I mentioned I can’t use Allocator.TempJob because my jobs are long running. Is that right? The NativeArrays contain data that is only used in the job and then disposed after the job completes so ideally they should be TempJob data. Is there any way to use Allocator.TempJob for long running jobs? I appreciate you’re help.
I added a few more details to my original post that may be relevant. I am using UnsafeList in the project. Whenever I immediately call jobHandle.Complete() after scheduling the jobs I get no warnings. The warnings only come when I schedule the jobs and then check if they are complete every frame and then call jobHandle.Complete() once jobHandle.IsCompleted returns true.
Your answer
Follow this Question
Related Questions
implicit downcast 'Object' to "UnityEngine.Quaternion" 1 Answer
why do i get this warining when there is a main camera? 0 Answers
Box Collider 2D -failed verification- warning even when the size is reasonable 2 Answers
Attempt to insert 9Slice RenderData twice warning in erroneous places 0 Answers
SendMessage cannot be called during Awake, CheckConsistency, or OnValidate 0 Answers