Search Unity

[Jobs][Lags] JobTempAlloc has allocations that are more than 4 frames old

Discussion in 'Data Oriented Technology Stack' started by dyox, Jan 18, 2018.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,043
    Sorry was meant to reply before but got caught up.

    So yeah the majority of the time this warning shows up it has nothing to do with container allocations and the message itself really gives you no feedback which is why it's such a confusing warning. From experience though, it's nearly always an issue with jobs and jobhandles, usually one being lost due to a different path in code being taken.

    It sounds like your issue might relate to some internal jobs related to the frame debugger, might want to file a bug report in that case.
     
    MNNoxMortem likes this.
  2. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    55
    Yes. And after more tests, it is clear that it is the problem of using SRP batchers with Frame Debugger. Turning off the SRP batchers makes everything fine.
     
    xoodZ likes this.
  3. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    187
    I experienced "JobTempAlloc..." warning with Addressable Asset System when I use textures with enabled option "Use Crunch Compression", both under Unity 2018 and 2019. Disable crunch compression fixed a problem for me.
     
  4. xoodZ

    xoodZ

    Joined:
    Jan 8, 2018
    Posts:
    17
    I also saw these errors in the console after the project was transferred to 2019.2. Previously, in 2018.4 these errors were not.
    I also get errors if the game is running, the statistics window is on, and I move objects in the scene.
    Disabling the statistics window and restarting Unity helped me.
     
  5. laeusnb

    laeusnb

    Joined:
    Jun 10, 2014
    Posts:
    71
    I'm seeing a report in the wild with massive "Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak" etc spam in the output log. It's a final build using Unity 2018.4.2f1. Anything I can do with this? Super hesitant to upgrade a shipping project to Unity 2019+, but if it's necessary, it can be done.

    Edit: this player's entire machine freezes, forcing a full restart.
    Edit 2: not using ECS or job system or any similar fancy stuff, and not seeing a single reference to job stuff when doing Find All in my solution.
     
    Last edited: Jan 31, 2020
  6. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    214
    @laeusnb When you say, out in the wild, do you mean in production run. If a temp job is created in a fixed update frame and then 4 regular update frames are run before the next fixed update frame (where the frame can be disposed) this will pop up. I found limiting my frame rate via VSync fixed this issue.
     
  7. laeusnb

    laeusnb

    Joined:
    Jun 10, 2014
    Posts:
    71
    Thanks -- I mean, a pre-release Steam build of the game. I also should have mentioned (and added an Edit) that I'm not using the job system or ECS at all.
     
  8. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,121
    Do you use the async navmesh package? I think that's where mine stem from. It's always just been an annoyance though, I've never had any crashes or user problems.
     
  9. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    566
    Yeah I get this message when using async back navmesh at runtime, not sure how to get rid of it
     
  10. kingstone426

    kingstone426

    Joined:
    Jun 21, 2013
    Posts:
    36
    I would also strongly advice against upgrading when close to release. Try pinpointing the problem. Can you reproduce the problem on your machine? The 4 frames warning may occur only on slower machines due to jobs taking more frames to complete, so maybe you can mimic your player's specs and setup.

    Also, Unity uses ECS under the hood for some stuff, and as others have mentioned, async navmesh baking is known to produce these warnings. But for me at least, it has not caused a complete freeze. It might be possible that the freeze and warnings are unrelated.
     
  11. dyox

    dyox

    Joined:
    Aug 19, 2011
    Posts:
    567
    It happens on high fps too.
    High or low config.
    4 frames, it's just not enough.
     
  12. laeusnb

    laeusnb

    Joined:
    Jun 10, 2014
    Posts:
    71
    I cannot reproduce it on my machine at all (and have had no reports of freezing/crashing from other playtesters). This player has a pretty beefy machine. I'll keep digging to see what it is. I do not use async navmesh. Thanks for the input.
     
  13. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    214
    If the player has a beefy machine, means his framerate is too high and some job Unity has created (probably in the fixed update part) is not being disposed within four Update frames. I wish they would fix this and not spam the console with this message. Or allow us to up the warning to 10 - 20 frames.
     
    laeusnb, dyox and malkere like this.
  14. Isuroku

    Isuroku

    Joined:
    Jul 23, 2015
    Posts:
    1
    I had this warning: "Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 12)" until I closed Tab Profiler. May be it's help somebody.
     
  15. cooloon

    cooloon

    Joined:
    Nov 25, 2014
    Posts:
    5
  16. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,121
    I'ts been a known issue since 2018 =o
     
  17. stevensrmiller

    stevensrmiller

    Joined:
    Oct 20, 2017
    Posts:
    189
    I have also been getting the "JobTempAlloc has allocations that are more than 4 frames old" warning. In my case, I have used the GetRawTextureData method on a Texture2D, and passed the pointer to the NativeArray it returns to my IJob struct. The job clears the texture, but I have plans for much more complicated drawings, many of which will take longer than four frames to complete. In my code here, I simply repeat the loop that clears the 512x512 texture ten times. It ends up taking about 240ms, and always generates the "more than 4 frames" warning.

    This is pretty surprising because the documentation for GetRawTextureData says this:
    So there is no allocation happening at all. Also, setting NativeLeakDetectionMode to Disabled has no effect.

    My code is below. I'm on the lastest LTS Unity, 2018..4.18f1. Should I report this as a bug?

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using Unity.Jobs;
    4. using Unity.Collections;
    5.  
    6. public class ChangeTexture : MonoBehaviour
    7. {
    8.     Job job;
    9.     JobHandle jobHandle;
    10.  
    11.     Texture2D tex;
    12.  
    13.     void Start()
    14.     {
    15.         tex = (Texture2D)GetComponent<Renderer>().material.mainTexture;
    16.     }
    17.  
    18.     private void OnMouseDown()
    19.     {
    20.         NativeArray<byte> pixels = tex.GetRawTextureData<byte>();
    21.  
    22.         MyJob job = new MyJob
    23.         {
    24.             pixels = pixels,
    25.         };
    26.  
    27.         jobHandle = job.Schedule();
    28.  
    29.         StartCoroutine(WaitForJob());
    30.     }
    31.  
    32.     IEnumerator WaitForJob()
    33.     {
    34.         while (jobHandle.IsCompleted == false)
    35.         {
    36.             yield return null;
    37.         }
    38.  
    39.         jobHandle.Complete();
    40.  
    41.         tex.Apply();
    42.     }
    43. }
    44.  
    45. struct MyJob : IJob
    46. {
    47.     public NativeArray<byte> pixels;
    48.  
    49.     public void Execute()
    50.     {
    51.         for (int r = 0; r < 10; ++r)
    52.         {
    53.             for (int i = 0; i < pixels.Length; i = i + 4)
    54.             {
    55.                 pixels[i] = 0xFF;
    56.                 pixels[i + 1] = 0xFF;
    57.                 pixels[i + 2] = 0xFF;
    58.                 pixels[i + 3] = 0xFF;
    59.             }
    60.         }
    61.     }
    62. }
    63.  
     
  18. stevensrmiller

    stevensrmiller

    Joined:
    Oct 20, 2017
    Posts:
    189
    Here's a rewrite of my code that replaces Unity's IJob system with .NET's Thread class. Not certain it guarantees memory coherence in the Texture2D's raw data.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Threading;
    3. using Unity.Collections;
    4. using UnityEngine;
    5.  
    6. public class ChangeTextureThread : MonoBehaviour
    7. {
    8.     Texture2D tex;
    9.  
    10.     void Start()
    11.     {
    12.         tex = (Texture2D)GetComponent<Renderer>().material.mainTexture;
    13.     }
    14.  
    15.     private void OnMouseDown()
    16.     {
    17.         NativeArray<byte> pixels = tex.GetRawTextureData<byte>();
    18.  
    19.         PixJob job = new PixJob
    20.         {
    21.             pixels = pixels,
    22.         };
    23.  
    24.         Thread jobThread = new Thread(job.Execute);
    25.         jobThread.Start();
    26.  
    27.         StartCoroutine(WaitForJob(jobThread));
    28.     }
    29.  
    30.     IEnumerator WaitForJob(Thread jobThread)
    31.     {
    32.         while (jobThread.IsAlive)
    33.         {
    34.             yield return null;
    35.         }
    36.  
    37.         tex.Apply();
    38.     }
    39. }
    40.  
    41. class PixJob
    42. {
    43.     public NativeArray<byte> pixels;
    44.  
    45.     public void Execute()
    46.     {
    47.         for (int r = 0; r < 10; ++r)
    48.         {
    49.             for (int i = 0; i < pixels.Length; i = i + 4)
    50.             {
    51.                 pixels[i] = 0xFF;
    52.                 pixels[i + 1] = 0xFF;
    53.                 pixels[i + 2] = 0xFF;
    54.                 pixels[i + 3] = 0xFF;
    55.             }
    56.         }
    57.     }
    58. }
     
    Last edited: Mar 1, 2020
  19. xibanya

    xibanya

    Joined:
    Nov 26, 2016
    Posts:
    11
    Hey, I'm getting this issue and I'm not using the jobs system at all, and I'm not aware of any plugin I'm using that does. How can I diagnose and get rid of this warning?
     
  20. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,121
    @Marco-Trivellato
    @Joachim_Ante
    @timjohansson
    All the pings because it's been years and this is still clogging up our output logs to no end! Running 2018.4.16 LTS, still full of this. Is this supposed to have been addressed? Why is there still no way to just turn it off?
     
unityunity