Search Unity

Bug Opening a scene immediately allocates 11GB of GFX Memory

Discussion in 'Editor & General Support' started by Matmat94, Jan 31, 2023.

  1. Matmat94

    Matmat94

    Joined:
    Dec 5, 2017
    Posts:
    2
    I'm trying to understand what is making Unity allocate so much memory before even initializing or rendering anything.

    Context : Unity 2020.3.42 on Windows 11 x64 with OpenXR enabled and URP pipeline.

    I have a startup scene, active and at this point Unity is taking 1.7GB of memory in the Task Manager.
    I have another scene added additively in the hierarchy and when I load it the Task Manager shows 6.4GB.
    Unloaded again, it goes back to 1.7GB.

    The second scene added additively contains disabled MeshRenderers, inactive Visual Effects, basically only a black occlusion plane that represents the ground.
    For all of the scripts that had [ExecuteInEditMode] I removed the attribute.

    Now with the Memory Profiler package I did a compare of the two snapshots:

    upload_2023-1-31_11-29-16.png

    As you can see, when Scene B is unloaded I have only 112MB of GFX memory and when it is loaded without scripts running it goes immediately to 11.30GB (and 6.40 GB in Task Manager).

    Where I am lost is when I see this normal memory usage in the Tree Map (snapshot B) :
    upload_2023-1-31_11-32-52.png

    We can see that there are no enormous objects that takes up lots of spaces. And the Unity scene file is only 700Kb.

    Then there is the "Objects and Allocations" tab, where I got this :
    upload_2023-1-31_11-37-36.png

    I'm not sure what it's supposed to mean.

    Finally all the Native Objects :
    upload_2023-1-31_11-42-7.png

    Is it possible that a native DLL would be responsible of allocating that much memory ?
    That DLL is not even supposed to be loaded when I load the Scene because all the scripts are disabled.
    The profiler says that the 11 GBs are part of tracked memory but can't show where.

    Any help would be appreciated!
    Thanks,
    Mathieu
     
  2. Matmat94

    Matmat94

    Joined:
    Dec 5, 2017
    Posts:
    2
    Update: I found that the culprit was approximately 26 Visual Effects in the scene each using the same asset, which contains 5-6 systems with maximum particles configured from 500 000 to 2 000 000 each (the asset is a sort of library where I use the effect I need with different event names).
    However, disabling the behaviour did not deallocate the memory.
    Even restarting Unity with the disabled Visual Effects still led to lots of GB allocated.
    I completely emptied the VFX asset and now the scene loading is very fast and nothing changes in the Task Manager.

    I don't know if this is supposed to be a bug or a feature, but it means I'm going to have to find a way to pool VisualEffects and reuse them for other scenes or something like that. I'll also try to reduce the number of systems depending on the effect needed.
    Also, it would have been great to know that the memory was coming from VFX allocations. Unless I missed it somewhere I don't have any means to know how much VFX is allocating in the system memory and the GPU memory.