Search Unity

How to track memory leaks?

Discussion in 'Entity Component System' started by Deleted User, Aug 12, 2019.

  1. Deleted User

    Deleted User

    Guest

    When a memory leak happens editor only prints:
    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak

    and
    To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations

    How we are supposed to track the source of the leak when it doesn't provide stacktrace or something?
     
    Antypodish likes this.
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    Yeah! Interested in this myself. I'm using the multiplayer package right now and I get this message in builds, not in editor which is weird. Not sure myself how to track this.
     
  3. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    Oh, I see, well what would be great is that it isn't logged to disc then.
    I think it doesn't bottleneck the game but it's a lot of IO. It quickly takes up some megabytes.
    Shouldn't this be an older bug? I'm running 2019.3.a5
     
  5. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    I've found it comes and goes with restarts/updates, I've rarely had it in later 2019 versions but others do. Could try another version or wipe the manifest and re-download packages if you really wanted to.
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Hmm. As I've posted before as far as I'm aware most internal alloc issues fixed and most instance that has been posted on the forum recently where people claim it's a Unity issue has been found to be a user issue instead.

    This warning usually comes not from container allocations but jobhandles.
    Another common issue is on mobile platforms people not using correct link.xml and something being stripped causing the issue.
    Any type of exception within the chain is going to cause it to break and require a restart of unity.

    I dont see these warnings much anymore and I have multiple projects all tested on 19.1, 19.2 and 19.3 (latest versions) without seeing any issues. They do pop up occasionally but it's always an issue with something i've done (an exception, forgot to properly chain a jobhandle, forgot to stop something being stripped etc.)

    Older packages or versions (a5 is pretty old alpha) might still have issues. I'd recommend updating.

    When they do appear they are extremely annoying to debug which I feel like needs improving

    -edit-

    actually i could be slightly wrong. i just remembered recently when I switched back to mono instead of il2cpp (which I usually use) just to test I started getting issues like this again so there are probably still internal issues relating to the build pipe. Even after switching back to IL2CPP they reappeared for a while (eventually disappearing in the build) so it seems very temperamental.

    If you don't get them in editor and get them in a build, there is little you can probably do except hope for a fix in future. any that pop up in editor though is usually an issue you can fix.
     
    Last edited: Aug 13, 2019
    JesOb, Enzi and RecursiveEclipse like this.
  7. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    Thanks for pointing me in the right direction. I think that's very likely in my case.
     
  8. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    I have use latest Unity 2019.2, use Mono in editor on Android platform, dont use jobs at all (dont write my own), use ECS on main thread in systems and have these errors in editor.

    Dont rememeber to see it in builds.