Search Unity

WebGL Garbage Collection

Discussion in 'Editor & General Support' started by mazumdarshouvik, Feb 23, 2019.

  1. mazumdarshouvik

    mazumdarshouvik

    Joined:
    Jan 31, 2019
    Posts:
    2
    Hi

    We are building an extensive webGL based games. The architecture currently is:

    We have a main scene with a bunch of global management scripts

    We load individual scenes as additive scenes

    Problem is after some time of game play , a lot of memory out of bound errors crop in and makes the game unusable. So few queries

    Does the GC run when a new additive scene is addes ? I read that in webGL the GC runs only when a scene is destroyed. However in our case the main scene never gets destroyed and only the additive scenes are getting destroyed while moving from one scene to another

    We are optimizing the individual scenes assets as per Unity’s documentation and blog but that is not helping us much as the app keeps crashing arbitrarily

    We made Unity Heap as 160 MB to support IE edge and Firefox but our asset sizes etc point to a comfort zone of 256 MB.

    What is the recommended Heap Size for WebGL that will support most browsers ?
     
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    • The GC runs every few frames.
    • Memory Fragmentation is a big issue on WebGL. Therefore wherever possible explicitly allocate continous memory blocks of minimal size and reuse them as compact as possible. Especially try to minimize the largest size of continous memory required - the larger your average block is the higher the chance is fragmentation will kill your memory layout.
    • Try wasm instead of asm if you do, this allows the memory to grow.
    • Explicitly use
    • Resources.UnloadUnusedAssets if you load anything from Resourfces.
    • Recommended size is 256MB, however you can grow to 1023MB with chrome 32 bit and ~1,4GB with chrome 64 bit.
    • Chrome is more restrictive than Firefox, therefore always also test in Chrome.
    • Analyze which assets actually contribute the most and remove any unecessary dependencies. Very likely your textures account for 1/3 to 2/3 of the total size.