Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug UIToolkit Build Memory Leak

Discussion in 'UI Toolkit' started by MousePods, Oct 30, 2023.

  1. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    802
    The previous memory leak seemed to be editor only. I found more memory leaks in build on WebGL and iOS.

    On safari, I can have just one label in a scene with a camera and the game will continuously rise in memory (watching activity monitor) until it crashes.

    It happens on all versions, LTS, Beta, and Alpha.

    Report: IN-59273

    This is just sitting in the editor with 2 labels and some visual elements on screen:

    Screenshot 2023-10-30 at 5.19.49 PM.png

    Is this a known issue? If it isn't, is there any possible way to work around this? This seems like a major issue that would stop any production app from being released?

    Thanks
     
    Last edited: Oct 30, 2023
    MartinTilo likes this.
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,408
    Are you sure you're not continuously recreating the Label and subscribing it to the GeometryChangedEvent (and the others listed in the References panel) without ever unsubscribing it? It's super easy to accidentally leak memory that way.

    You might want to debug (or add log events) to the code where the Label is created/the event subscription is registered.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,408
    Why I know how easy it is to leak memory that way? Well, while looking into the original Mesh Leak bug discussed in the other thread and trying to fix it, I temporarily changed it so I leaked via event subscriptions :D
     
    Findeh likes this.
  4. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    802
    I wish it was just me :(

    I am pretty sure what I reported is a static scene with no code. Also, I know 1000% there is no code in the scene with just a single label on webgl and safari.

    Here is Activity Monitor on macOS (latest version) showing the memory grow on webGL with a single, static label in the scene, no code at all. This will go up infinitely until it crashes.

    Here is a video of it (hard to see since its a thin cut of my screen) \/


    Screenshot 2023-11-02 at 10.59.08 AM.png
    Screenshot 2023-11-02 at 10.59.12 AM.png
    Screenshot 2023-11-02 at 10.59.18 AM.png
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,408
    hmm, so there is no script instantiating this or anything?

    fair enough, that's odd. I guess that bug will require an investigation then. It is still independent of the Mesh leak though.
     
  6. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    802
    There are no scripts :/

    Its a very frustrating leak as I cannot work around it as far as I can tell.

    Thanks for the info tho! Hopefully it can be found and fixed as this bug probably affects everyone as I tested this on LTS, Tech, Beta, and Alpha.
     
    Last edited: Nov 2, 2023
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,408
    Yeah, I hope so, I brought it to the attention of the UI team :)
     
    MousePods likes this.