Repository navigation
Description
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

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

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

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

-
Once the memory heap is generated, it will link the detached element to the objects in the memory tool

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.
- Multiple
markers-panel-action-filter-containerandswitch-outputSteVen Batten (@sbatten) - Multiple
status.languageStatusspan andcodicon codicon-bracket wigglespan nodes are ref'ed by mutation observers inSuggestDetailsOverlayJohannes Rieken (@jrieken) - DOM node for monaco editor in
AccessibilityHelpWidgetIsidor Nikolic (@isidorn)
Activity
re #146841. Fix actionbar memory leak.
re #146841. allow single action view item to be disposed properly.
fix leaking observer, #146841
jrieken commentedon Apr 6, 2022
👏 wow, this is a pretty cool tool
isidorn commentedon Apr 6, 2022
Peng Lyu (@rebornix) super cool. And thanks for fixing the
ActionBarbug which I probably introduced originally :)fyi Henning Dieterichs (@hediet) for AccessibilityHelpWidget
re #146841. Fix actionbar memory leak.
re #146841. allow single action view item to be disposed properly.
fix leaking observer, #146841
bpasero commentedon Dec 6, 2023
Using this tool on insiders.vscode.dev with Edge, I see a detached
HTMLDivElementwhich 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):Does someone have an understanding where these are captured exactly?
//cc Henning Dieterichs (@hediet) Alexandru Dima (@alexdima)
10 remaining items
Release accessible view listeners per show instead of on dispose (#33…
Stop chat progress signals once the request settles (#337883)
Release previous chat models when the chat view switches sessions (#3…
Release inline request edit input and listeners when editing finishes (…
Don't retain the faded out editor message widget (microsoft#337854)
Don't retain the last KeyboardEvent in ModifierKeyEmitter (microsoft#…
Release widget DOM nodes when an editor view is disposed (microsoft#3…
Release the input focus tracker once the input blurs (microsoft#337856)
Only remember sticky scroll mouse targets inside the widget (microsof…
Release accessible view listeners per show instead of on dispose (mic…
Release previous chat models when the chat view switches sessions (mi…
Release inline request edit input and listeners when editing finishes (…
Stop chat progress signals once the request settles (microsoft#337883)