Skip to content

Detached DOM nodes memory leak #146841

Closed
Closed

Description

@rebornix

The Edge Dev Tools now offers Detached Elements tool to help detect memory leaks. The tool is a good addition to the memory heap tool but it's analyzing from a different angle. SteVen Batten (@sbatten) and I spent some time digging into this tool and fixed memory leaks in the ActionBar successfully. Here is how we tackle the leaks in action bar:

  • Open vscode (scripts/code-web.sh) in Edge

  • Play around with it for a bit

  • Open Edge Dev Tools -> ... -> More Tools -> Detached Elements
    image

  • Click the trash icon to trigger manual GC and click the first button to collect all detached elements
    image

  • It found 100+ detached elements which can not be GC'ed. We easily found dozens of markers-panel-action-filter-container
    image

  • To analyze why they can't be GC'ed, click the Eye icon on the top toolbar to generate a heap dump
    image

  • Once the memory heap is generated, it will link the detached element to the objects in the memory tool
    Screen Shot 2022-04-05 at 1 37 19 PM

Turned out we register a global DOM listener for every ActionViewItem and store it in ActionBar disposable store. When the ActionViewItem is disposed, the DOM listener will be not disposed/cleared until the ActionBar is disposed.


With the ActionBar leaks fixed, there are still 30+ detached DOM nodes not GC'ed. Not every one is necessarily memory leak (for example, if you are using ListView, it will hold refs to template DOM nodes) but some of them are duplicated elements.

Activity

  1. added
    debt
    on Apr 5, 2022
  2. added 2 commits that reference this issue on Apr 5, 2022
  3. jrieken commented on Apr 6, 2022

    @jrieken
    Contributor

    👏 wow, this is a pretty cool tool

  4. isidorn commented on Apr 6, 2022

    @isidorn

    Peng Lyu (@rebornix) super cool. And thanks for fixing the ActionBar bug which I probably introduced originally :)
    fyi Henning Dieterichs (@hediet) for AccessibilityHelpWidget

  5. added 3 commits that reference this issue on Apr 6, 2022
  6. added
    freeze-slow-crash-leak
    on Dec 5, 2023
  7. bpasero commented on Dec 6, 2023

    @bpasero
    Contributor

    Using this tool on insiders.vscode.dev with Edge, I see a detached HTMLDivElement which seems to be the monaco editor every time I switch between 2 tabs (which I find surprising because we do reuse the same editor instance in the same editor group):

    image

    Does someone have an understanding where these are captured exactly?

    image

    //cc Henning Dieterichs (@hediet) Alexandru Dima (@alexdima)

  8. 10 remaining items

  9. added this to the 1.140.0 milestone on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debtfreeze-slow-crash-leakperf-bloat

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions