Search Unity

Jobs that take longer than 4 frames.

Discussion in 'Entity Component System' started by pk1234dva, Dec 12, 2021.

  1. pk1234dva

    pk1234dva

    Joined:
    May 27, 2019
    Posts:
    84
    I've went through this thread:
    https://forum.unity.com/threads/job...tions-that-are-more-than-4-frames-old.513124/
    but it's still not completely really clear to me.

    I would like a clear answer on this - are jobs that take longer than 4 frames officially supported, meaning I can ignore the warnings, and safely assume Unity won't delete any internally allocated memory inside the job, or do any sort of harm? (Assuming I'm using persistent allocators for all things that I myself explicitly allocate, for example, and I correctly deallocate them.)

    Since jobs are used internally for various things and these warnings can happen for people not really using their own jobs or allocating their own native containers, I would assume these warnings are safe to ignore.

    Deleting memory that is still being used in a job seems like a pretty big issue that would likely cause crashes, so I have a hard time imagining something like that would even be possible... But seeing "Deleting allocation that is older than its permitted lifetime..." makes me a bit worried, so I'd like to make sure this doesn't mean the memory could actually be deleted while the job is still running.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Jobs work fine for more than 4 frames work fine and should not even trigger leak warnings (except IJobParallelForDeferred or whatever it's called now which seems to use TempJob memory.)

    If you're triggering leak warnings you're using TempJob memory in there somewhere (instead of Persistent) and is likely a sign you're doing something wrong.

    I have a whole set of jobs that run up to a second long without any leak warnings.
     
  3. pk1234dva

    pk1234dva

    Joined:
    May 27, 2019
    Posts:
    84
    I think got the same warning as mentioned in the thread I linked:
    "Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak"
    while only using Allocator.Persistent everywhere, with the exception of a few TransformAccessArray and using the Mesh.MeshDataArray result of a Mesh.AcquireReadOnlyMeshData call, for neither of which I can set the allocator explicitly.

    Could the warning happen because of one of those?
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    I feel like TransformAccessArray should only be valid for 1 frame because transforms can change every frame and need to be re-synced.

    But either way you can't use any data from the Entity world in a job that lasts more than 1 frame. You need to duplicate it then write it back after the job is complete.
     
  5. pk1234dva

    pk1234dva

    Joined:
    May 27, 2019
    Posts:
    84
    Thanks, I'll give it a try.