monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] Editor dispose erroring in async.ts

Open kazepreaux opened this issue 3 years ago • 4 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Code

// The Monaco Editor can be easily created, given an
// empty container and an options literal.
// Two members of the literal are "value" and "language".
// The editor takes the full size of its container.

const mon = monaco.editor.create(document.getElementById('container'),  {
                autoClosingBrackets: "never",
                autoClosingQuotes: "never",
                automaticLayout: true, // severe performance impact, but avoiding CSS for now
                language: 'csharp',
                lineNumbers: "off",
                minimap: {
                    enabled: false,
                },
                renderValidationDecorations: "off",
                scrollbar: {
                    alwaysConsumeMouseWheel: false,
                },
                suggest: {
                    showStatusBar: true,
                    showWords: false, // There is a weird interaction between editors without this being set to false.
                    snippetsPreventQuickSuggestions: false,
                },
                theme: "vs",
                value: "22",
            });


mon.dispose();

Reproduction Steps

Paste the code on the playground Open a console and put a breakpoint in async.ts line 274 in the cancel() method:

cancel(): void {
  this.cancelTimeout();
  
  if (this.completionPromise) {
	  if (this.doReject) {
		  this.doReject(new CancellationError());  // HERE
	  }
	  this.completionPromise = null;
  }
}

Press the Run button

It should hit the breakpoint

Actual (Problematic) Behavior

The actual problem is that it would cause a memory leak, which we could see when testing

Expected Behavior

The async dispose should happen correctly, not reject.

Additional Context

No response

kazepreaux avatar Jul 27 '22 15:07 kazepreaux

Can you elaborate why you think this causes a memory leak?

hediet avatar Jul 28 '22 18:07 hediet

Hi,

We use Monaco editor as part of one of our components written in AngularJS.

For every of our components, we add a tag onto the scope so that we can detect if anything is left over after destroying the scope.

Part as part of our destroy, we dispose of the monaco editor, however, when we run our tests, we find tags left over, with a promise help for async.js. How we do it is we run our tests, open de dev tools, perform a gc (click few the button), then perform a heap snapshot. We then search for tag, and find leftover tags.

image

I hope this helps.

Louis

kazepreaux avatar Aug 01 '22 15:08 kazepreaux

Can you provide steps of how to reproduce the memory leak in the playground?

hediet avatar Aug 03 '22 15:08 hediet

I will spend some time on it and try to get the leak on the playground. It might take some time hehe.

kazepreaux avatar Aug 03 '22 16:08 kazepreaux

Hey @hediet, this issue might need further attention.

@kazepreaux, you can help us out by closing this issue if the problem no longer exists, or adding more information.

github-actions[bot] avatar Feb 07 '23 15:02 github-actions[bot]

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

github-actions[bot] avatar Feb 15 '23 12:02 github-actions[bot]