Search Unity

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

Question Help With UI Toolkit Memory Leak, TooltipEvent?

Discussion in 'UI Toolkit' started by ryan-lintott-0, Nov 21, 2023.

  1. ryan-lintott-0


    Jan 18, 2022

    I'm investigating a possible visual elements memory leak in our project. The memory footprint of visual elements continues to increase as you play. I know events are a common source of memory leaks, and it looks like almost all the elements have this TooltipEvent (see attached image), I'm wondering where this comes from and if it might be the cause of the leak? There is nowhere in the code where a TooltipEvent is explicitly registered, though. In case it's relevant, this is being profiled in a development build.

    Screenshot 2023-11-21 123410.png

    Unity Version: 2021.3.24f1

    Thank you in advance for any help
  2. MartinTilo


    Unity Technologies

    Aug 16, 2017

    Yes that view needs some improvements, some of which I'm working on atm as part of learnings I took from a memory leak investigation recently. Especially UI TK related references get a bit tricky in there as they tend to get very deep and nested and the view has some filters in place, some faulty, some a current mathematical necessity of the approach, as we need to stop processing references after 2k of them have been parsed (without any indication where it stopped and why). (I have a snapshot with a case where 5k objects lead to 4 Trillion references that need to be parsed for the full path to root. I posted some details here if you're curious.)

    Back to your case, in how far are your VisualElements leaked, i.e. what makes you think that they are leaked? Does their number keep increasing between snapshots?

    Do the references go deeper when you unfold the nested Visual Element array at the bottom of the list? Maybe something else than the event is keeping them alive and the Tooltip event is a result of them somehow still being in the UI?
    Or maybe they got "removed" (albeit uncleanly) while hovered over?

    It could of course be an issue within the engine that would require a bug report and a fix from our side, but I want to dig a bit further into this here first :)
    HugoBD-Unity likes this.
  3. SimonDufour


    Unity Technologies

    Jun 30, 2020
    While event listener are often the culprit, I would really try to find out who is the owner of the list :
    MartinTilo likes this.