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.

Question IL2CPPMemoryAllocator in WebGL

Discussion in 'Web' started by G33RT, Aug 29, 2023.

  1. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    We seem to be observing memory leaks in WebGL builds (which we do not observe in IL2CPP Windows or Mac builds)

    Memory Profiling shows that IL2CPPMemoryAllocator seems to be growing constantly. We cannot find any info on this, however:

    upload_2023-8-29_9-7-3.png

    Any ideas?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,807
    Which version of Unity are you using?
     
  3. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    Profiling was done with 2022.3.4
     
    JoshPeterson likes this.
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,807
    Unfortunately we don't have too much more visibility below this metric. If IL2CPP is allocating memory over time, that usually means the C# code is doing a number of reflection calls. This is different from heap-allocated memory that the GC can reclaim. The IL2CPP runtime needs to do separate memory allocations in order to support the reflection system.

    But this is just a guess. I'm unclear why this would only show up on WebGL builds. Is there some different C# code executing in the project for WebGL?
     
  5. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    Thanks for your quick reply, Josh. You are right, we see similar behaviour in other IL2CPP builds, albeit to a lesser extent. Your hint about Reflection is something we will investigate, although we have tried to avoid it during development as WebGL supposedly does not support it. But under the hood maybe there is some Reflection going on anyway that we are not aware of. Thanks for the lead!
     
    JoshPeterson likes this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,807
    Note that IL2CPP and WebGL do support reflection in general. They don't support System.Reflection.Emit, specifically, though.

    With that said, reflection can be costly in a number of ways, so it is worth avoiding if possible. Please let me know if you track down the cause! I'd love to know.