Skip to content

Promise memory leak when scrolling in notebook #276605

@SimonSiefke

Description

@SimonSiefke

Expected behaviour

When scrolling up and down in a notebook, the number of promises stays the same

Actual behaviour

When scrolling up and down in notebook, the number of promises increases each time, specifically this deferred layout promise

// notebookCellLayoutManager.ts
const deferred = new DeferredPromise<void>();
const doLayout = () => {
	const pendingLayout = this._pendingLayouts?.get(cell);
	this._pendingLayouts?.delete(cell);

Scrolling up and down 97 times:

{
  "promisesWithStackTrace": [
    {
      "count": 970,
      "properties": [
        {
          "name": "[[PromiseState]]",
          "type": "string",
          "value": "fulfilled"
        },
        {
          "name": "[[PromiseResult]]",
          "type": "undefined",
          "value": "undefined"
        }
      ],
      "originalStack": [
        "src/vs/base/common/async.ts:1741:11",
        "src/vs/workbench/contrib/notebook/browser/notebookCellLayoutManager.ts:47:19",
        "src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts:2373:34",
        "src/vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput.ts:785:22",
        "src/vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput.ts:553:9",
        "src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts:122:32",
        "src/vs/platform/instantiation/common/instantiationService.ts:169:17",
        "src/vs/platform/instantiation/common/instantiationService.ts:135:33"
      ]
    }
  ]

Similarly, the leaked closure functions measure shows these results:

{
  "namedFunctionCount3": [
    {
      "count": 1499,
      "delta": 100,
      "name": "Bd",
      "sourceLocation": "vscode-file://vscode-app/workspaces/vscode-memory-leak-finder/.vscode-test/vscode-linux-x64-1.105.1/resources/app/out/vs/workbench/workbench.desktop.main.js:29:100170",
      "originalLocation": "src/vs/base/common/observableInternal/debugName.ts:28:18",
      "originalName": "DebugNameData"
    },
    {
      "count": 999,
      "delta": 970,
      "name": "T$e",
      "sourceLocation": "vscode-file://vscode-app/workspaces/vscode-memory-leak-finder/.vscode-test/vscode-linux-x64-1.105.1/resources/app/out/vs/workbench/workbench.desktop.main.js:32:3415",
      "originalLocation": "src/vs/base/browser/dom.ts:310:13",
      "originalName": "AnimationFrameQueueItem"
    },
    {
      "count": 990,
      "delta": 970,
      "name": "anonymous",
      "sourceLocation": "vscode-file://vscode-app/workspaces/vscode-memory-leak-finder/.vscode-test/vscode-linux-x64-1.105.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1905:166551",
      "originalLocation": "src/vs/workbench/contrib/notebook/browser/notebookCellLayoutManager.ts:103:35",
      "originalName": "NotebookCellLayoutManager.layoutNotebookCell"
    },
    {
      "count": 990,
      "delta": 970,
      "name": "r",
      "sourceLocation": "vscode-file://vscode-app/workspaces/vscode-memory-leak-finder/.vscode-test/vscode-linux-x64-1.105.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1905:165917",
      "originalLocation": "src/vs/workbench/contrib/notebook/browser/notebookCellLayoutManager.ts:48:19",
      "originalName": "doLayout"
    }
  ],
  "isLeak": true
}

Additional information

Test script for leaked promises:

git clone git@github.com:SimonSiefke/vscode-memory-leak-finder.git &&
cd vscode-memory-leak-finder &&
npm ci &&
node packages/cli/bin/test.js --cwd packages/e2e   --only notebook.code-scrolling --runs 97 --check-leaks --measure promises-with-stack-trace --run-skipped-tests-anyway --measure-after &&
cat .vscode-memory-leak-finder-results/promises-with-stack-trace/notebook.code-scrolling.json

Test script for leaked closures:

git clone git@github.com:SimonSiefke/vscode-memory-leak-finder.git &&
cd vscode-memory-leak-finder &&
npm ci &&
node packages/cli/bin/test.js --cwd packages/e2e   --only notebook.code-scrolling --runs 97 --check-leaks --measure named-function-count3 --run-skipped-tests-anyway --measure-after &&
cat .vscode-memory-leak-finder-results/named-function-count3/notebook.code-scrolling.json

Other

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.105.1
  • OS Version: Ubuntu 25.04

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions