Search Unity

StaticBatchingUtility - how to free up allocated resources?

Discussion in 'General Graphics' started by DaveL99, Jan 20, 2020.

  1. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    On additively loading a scene, I am creating a lot of procedural geometry and placing down a lot of static prefabs in that newly loaded (and active) scene. I'm then using StaticBatchingUtility.Combine to batch those together, which works great.

    However, when the scene is unloaded, and all game objects containing the original meshes - and also the combined static meshes - are destroyed, my app is leaking memory. The memory profiler shows mesh allocations from the combined static meshes are not getting freed up.

    What (if anything) am I doing wrong? How are we supposed to ensure that these allocations are freed?

    There was a bug report raised by another person on this matter a few years back, unfortunately it has been closed as "Won't Fix" without any comment or explanation that I can see:

    https://issuetracker.unity3d.com/is...-combine-leaks-memory-with-combined-mesh-data

    We are using Unity 2019.1.5. Any help would be greatly appreciated.
     
  2. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    In case it helps anyone else... So fortunately in my situation I am able to just call Resources.UnloadUnusedAssets () after unloading my additive scenes, and that appears to deallocate the combined mesh data.

    Kinda feels like there should really be some other way though...