Search Unity

Bug 2022.3 Editor memory leak when Application.runInBackground is set to false

Discussion in 'Editor Workflows' started by BBO_Lagoon, Jan 22, 2024.

  1. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    Hi,

    I have a huge memory leak in my game (Editor only) since I upgraded my project from 2021.3.33 to 2022.3.17
    The bug is here only when I set Application.runInBackground to false and I un-focus the editor for a while.

    After near 30s of un-focus, the memory of Unity Editor in the Windows Task Manager start to grow (near 50Mo / sec) and after some time the PC crash as Unity Editor takes all the RAM.

    For now I forced Application.runInBackground to true while in Editor, but it could be nice to fix the bug.

    I tried to reproduce the bug on a blank new 2d URP project and the bug is not present so it should be something on the project configuration, or something in the code.

    Someone know how I could track this leak ?
    I tried with the memory profiler but as Unity get back the focus the RAM is released so I can take a snapshot while the RAM usage is big.

    Any help appreciated ;)

    Environnement:
    Windows 11 Pro (23H2)
    Unity 2022.3.17f1
    Platform Android
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    You could use MemoryProfiler.TakeSnapshot API to take that snapshot from code x seconds after I looseFocus to see what it grows
     
  3. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    Hi @MartinTilo, thanks for the reply but how can I delay the snapshot if the code is not running ?
    Update() are not called when I lose focus and runInBackground is false, and I think async will not work too.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Ah, sorry yeah I misread it as happening when it's the other way around... I think then you're only left with taking the snapshot on focus loss and regain from code and see if it's already unloaded then and if not compare the 2.

    Otherwise... Might be worth a bug report? You're not starting any kind of background processes, right?
     
  5. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    Yes I wanted to report a bug but I'm not able to reproduce the bug on a small project yet, it's why I ask for help to find a way to find the origin of the bug ;)
    As the bug wasn't there with Unity 2021 it should be something on the Unity side, but where ?
    I think I'll try to move things from my main project to the new one little by little and see when it breaks ;)
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    That, or you could wait unitil the release of 2022.3.19f1 EOM, because it could also be related to UUM-41806, also see this thread.l:
     
  7. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    One more thing found about the bug, it only appears if the scene view is shown.
    • If only the game view is shown, there is no memory leak.
    • If only the scene view is shown or game view + scene view, the memory leaks is there.
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Do you have any Editor tools that register to the update or Sceneview repaint?
     
  9. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    I have one EditorWindow script with an Update function but the bug is still there after closing it.
    I don't have any scripts that register to an Update or SceneView repaint I think, do you talk about
    SceneView.duringSceneGui and EditorApplication.update or is it something else ?
     
    MartinTilo likes this.
  10. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    Ok, I've managed to reproduce the bug on a small project, I just created a bug report, Id: IN-66750.
     
    MartinTilo likes this.
  11. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Yeah, that's the events I was thinking off, thanks for filing a report :)
     
  12. SimonFearn

    SimonFearn

    Joined:
    Jan 16, 2020
    Posts:
    4
    MemoryProfiler.TakeSnapshot - Just comes back as 'Unknown' for the leak in the graph. Really helpful!

    In Task Manager, the leak is showing up under 'Shared GPU Memory' - Looks like it may have something to do with RenderTextures?
     
  13. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    What Unity version are you on?
    Render Textures should have their GPU memory properly reported as of 2022.2.16f1+