reduce impact of memory leaks related to editor #219297
Open
+18
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Helps with #218077
Changes
This PR changes the editor dispose function to recursively clear all child elements of the editor dom node.
DOM nodes hold strong references to parent node, sibling nodes and child nodes. When a memory leak occurs in a child component of the editor (e.g.
Minimap
,GlyphMarginWidgets
,TextAreaHandler
, ...) the editor dom (linked to the child dom) is leaked as well.By recursively clearing all editor child elements, only the child elements will be leaked.
Reducing impact of memory leaks
While this doesn't fix any memory leak, it reduces the impact of memory leaks related to the editor. For example, when opening an editor 197 times, the number of leaked dom nodes is much lower than before:
Making it easier to find the cause of editor memory leaks
With less leaked dom nodes, it could make it easier to find the cause of memory leaks related to the editor. For example, these are the detached dom nodes now when opening an editor 197 times:
It seems there is a memory leak related to the
editor background
and/oreditor margin
component.Performance
Clearing all dom nodes recursively has a performance overhead of ~1ms to ~1.8 ms on my machine. On the other hand, garbage collection could potentially be faster.
Test Script for measuring canvas count
Test Script for measuring detached dom nodes
Test Results
The number of canvas elements now stays pretty much constant: