Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question WEBGL Memory limits

Discussion in 'Web' started by beatdesign, Mar 1, 2023.

  1. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    I read that WebGL has a 2GB Heap limit. What value should I track in my application in order to see if I'm reaching that limit?
    • Total reserved memory
    • System used memory
    • GC used memory
    • Total used memory
    • GetMonoUsedSize
    • GetMonoHeapSize
    Any suggestion?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,316
    That 2GB limit is imposed by the browser for each tab, and this includes memory for everything on that tab - cache, images, html, javascript, the unity app and so on. Don't expect to be able to use all of that!

    Depending on the target platform you will be having a hard time getting anywhere close to that, especially if you build for mobile you want to make sure memory usage is below 512 MB for the Unity app itself (maybe even altogether to be on the safe side, so don't embed in a complex webpage).

    There's also the issue of memory fragmentation as allocating more memory beyond the initial allocation requires that requested free memory to be contiguous. So you cannot rely on any allocation beyond the initial memory budget to succeed, thus it's best to stay well below that initially defined budget.

    Best practice is to use the Firefox profiler, as mentioned here: https://forum.unity.com/threads/profiler-for-webgl.997991/

    And you'll find the best memory debugging infos in here: https://forum.unity.com/threads/how...alone-webgl-application.1265891/#post-8057897
     
    AdamandEveStudios and beatdesign like this.