Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Bug Opening a scene immediately allocates 11GB of GFX Memory

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

  1. Matmat94


    Dec 5, 2017
    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:


    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) :

    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 :

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

    Finally all the Native Objects :

    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!
  2. Matmat94


    Dec 5, 2017
    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.