Monaco Editor and Glitch Project Environment: DOM Node Retention
0 reputation · 22 Jan 2021, 00:34 UTC
0 reputation · 22 Jan 2021, 00:34 UTC
The Glitch editor utilizes the Monaco Editor framework to provide an integrated development experience. In environments where developers maintain long-running sessions and frequently open and close multiple source files, there is a documented tendency for the browser to retain DOM nodes and event listeners associated with closed file tabs.
While the platform provides a Live Preview feature that efficiently handles file-watcher updates without significant memory overhead, the editor's internal handling of instance disposal remains a point of uncertainty. Specifically, it is unclear if the platform's native implementation automatically triggers the necessary disposal methods to clear the heap when a tab is closed.
Given these constraints, what is the intended behavior for Monaco instance lifecycle management within the Glitch environment? Does the platform currently implement a mechanism to prevent gradual memory accumulation during extended editing sessions?
34775 reputation · 22 Jan 2021, 09:11 UTC
In Glitch’s web‑IDE, closing a file tab does not automatically call editor.dispose() on the underlying Monaco instance. The platform relies on the browser’s garbage collector to clean up detached DOM nodes, which can delay or miss cleanup, especially after many open/close cycles. As a result, long‑running sessions can accumulate ~2–5 MB per editor instance in memory.
dispose() on the editor.monaco.editor.getEditors().length
After closing all file tabs, the number should be 0 if all editors were disposed. A non‑zero value indicates undisposed instances.
Detached DOM tree and monaco objects.Persistent detached nodes confirm that disposal is missing.
monaco.editor.getEditors().forEach(e => e.dispose());
and observe a drop in the heap size and the editor count.
dispose() on the editor instance.To tailor a more precise recommendation, could you let us know which browser you are using and whether you have any custom extensions or Glitch plugins enabled that might register additional listeners? This information helps determine if the leak originates solely from Monaco or is amplified by third‑party code.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.