Search Unity

Question Strange Memory leak on 2022.3.x

Discussion in 'Windows' started by commonblob, Jul 13, 2023.

  1. commonblob

    commonblob

    Joined:
    Apr 24, 2015
    Posts:
    20
    Hi all,

    So this is an odd one. My game when run on 2021.3, memory sits around 1.3GB on launch. However, ive had reports since making changes over the last couple of months that some users are seeing around 10GB.

    I got one user to do a memory capture with the Unity 2022.3.4f1 memory profiler, and it shows memory usage at around 1.6GB, however his task manager claims it is using 10GB.

    Im guessing that this is because the leak is outside of my code. Is there anyway to track this leak?
    My external DLLs that I use are Steam Audio (already tried downgrading this), Steamworks SDK 1.57 (already tried downgrading this too).

    He also ran it once and it didnt leak memory.
    Just not quite sure how to deal with this, I guess I could try downgrading to 2021.3 again, but that would mean rewriting my navmesh stuff and a few other bits, which isnt ideal.
     
  2. commonblob

    commonblob

    Joined:
    Apr 24, 2015
    Posts:
    20
    0 changes to code
    Changed version to 2021.3.28f1
    Recompiled
    Memory leak gone.
    Guess that settles what version im sticking on for a while!
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,681
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Were you using the 1.0 (or 1.1.0-pre.1) version of the Memory Profiler package to look at a a capture from a 2022.3 Player? Because that should get all committed memory reported from the OS. Native plugin memory would show up as Untracked, but it should all be accounted for as part of the committed memory, even if there isn't much more info. (2023.1+ can break even that untracked amount down a bit further and help provide some context for what that is. For more details see this blog post and the forum thread it links to and please ignore the mentioning of 2022.2+ captures having that extra data, that's a mistake in the blog post that still needs fixing)

    So Total Committed should at least be as much as what Task Manager says and Process Explorer could help break down a bit more what kind of residency status that memory is made up of.

    Beyond that, the tool that @Tautvydas-Zilys mentioned then should give you even more detail on that untracked memory.
     
  5. LunarBullet

    LunarBullet

    Joined:
    Jul 22, 2020
    Posts:
    4
    when i have two game windows the game ram goes crazy, like unity starts growing from 1gb to 5 gb to 10 to then 16 to then crashing my system lol, cant have two game windows at the same time
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    @LunarBullet when you say two Game Windows, do you mean Game Views in the Editor, or two windowed Standalone Player instances?

    Also, have you tried to take a memory snapshot of this? If it is growing out of control too quickly, you could use the MemoryProfiler.TakeSnapshot API to trigger the capture from code.

    Or have you tried using the Windows Performance Analyser that Tautvydas mentioned?

    And: does it also leak with just one, but slower?
     
  7. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    I found “the” memory leak on 2022.3.x. I don’t know if its the same one as the OP but its been around since 2022.1 beta and I am surprised nobody has noticed it.

    I posted about it here: https://forum.unity.com/threads/2022-3-9-uielements-memory-leak.1491019/

    Is it possible to launch a production ready game with this type of memory leak? I never have had to experience this before but it seems extremely bad. It makes safari on webgl crash quickly.
     
    Last edited: Sep 12, 2023
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    No. I mean, there are ways to mitigate this by not instantiating new UI into a UIDocument continuously but that's less than ideal. BUT, thankfully you don't have to.

    Because this bug has already been fixed in 2022.3.10f1 and was tracked under UUM-46520
     
    MousePods likes this.
  9. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    I'm also quite certain that this was not the same issue as what this thread was originally about.
     
  10. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Dang :(. That is good and bad news then. I hope the OP figures out their issue but at least its one less leak they surely have. Thanks!
     
    MartinTilo likes this.
  11. TwoYen

    TwoYen

    Joined:
    Oct 17, 2017
    Posts:
    5
    I am having the exact same problem. When I Drag out the Scene view or the Game view or any view actually, thus having "2 windows", or even when I splitscreen the scene and game view in the same window. The RAM bumps up rapidly and crashes my computer.

    I am fairly sure this happened after updating from 2021.3.25f1 to 2022.3.8f1

    edit: I've just read that something got fixed in 2022.3.10. I'll try that out right away.

    edit2: Yep that fixed it.
     
    Last edited: Sep 28, 2023
    MartinTilo likes this.
  12. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    36
    @TwoYen were you getting the same issue I have mentioned on this thread, please let me know. I have been stuck on this since weeks and do not know how to fix this. Please confirm that mine issue is same as yours and which got fixed by upgrading Unity to 2022.3.10f1.
    Thanks
     
  13. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    I doubt they are related.
     
  14. seantheredstoner

    seantheredstoner

    Joined:
    Mar 8, 2022
    Posts:
    2
    I am having a memory leak issue on 2022.3.16f1
     
  15. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    I'm not aware of any further leaks there and can't even attempt to help you without any information, nor see how that would be related to the original post of this thread. Have you tried analysing it with the Memory Profiler?
     
  16. avita_work

    avita_work

    Joined:
    Jan 5, 2022
    Posts:
    4
    We are having a memory leak issue on the Windows il2cpp build of 2022.3.20f1, too!

    We use the following repositories with Google MediaPipe for our development:
    https://github.com/homuler/MediaPipeUnityPlugin

    The attached images are the results of a Windows il2cpp build of this project on 2022.3.20f1 and 2021.3.28f1, observed in the profiler after about 12 hours! In 2022.3.20f1, "Total Used Memory" increases to 1.5GB and "GC Used Memory" to 1.32GB. (In 2021.3.28f1, it does not increase much.)

    I analyzed using Memory Profiler on 2022.3.20f1, and the "Managed Reserved" is only increasing, as shown in the other attached image.

    The MediaPipeUnityPlugin performs GC Allocation in a thread that is not the main thread, so that may have something to do with it.

    Do you know what it is?
     

    Attached Files:

  17. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    A thread local might be holding on to that memory in a way that the memory profiler can't see it as referenced. I've seen that before with managed allocations in a thread. You could check what happens if you stop and restart the thread for that plugin?
     
  18. avita_work

    avita_work

    Joined:
    Jan 5, 2022
    Posts:
    4
    I tried to stop updating that plugin thread and the strange memory leak stopped. Indeed, it seems likely that the native plugin was holding memory.
    However, it is true that this event does not occur in 2021.3.35f. Was there some update between 2021.3 and 2022.3 that dealt with native plugins?
     
  19. avita_work

    avita_work

    Joined:
    Jan 5, 2022
    Posts:
    4
    I also built this plugin on a Mono build to test it out. As a result, I have discovered that this does not occur in the Mono build, but in the Windows il2cpp build. So I suspect that this is not a bug caused by the plugin, but by using the native plugin with the Windows il2cpp build.
     
  20. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    In that case, it may be worth filing a bug report.
     
  21. avita_work

    avita_work

    Joined:
    Jan 5, 2022
    Posts:
    4
    OK! I'll try to file a bug report. Thank you!
     
    MartinTilo likes this.