Skip to content

Fix cellPart toolbar event listener memory leak #253762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 2, 2025

Problem

A memory leak was occurring in notebook cell toolbars where event listeners were accumulating and not being properly disposed when cells were unrendered. The error stack trace pointed to:

at bge.D in ./file:/Users/cloudtest/vss/_work/1/s/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts:231:23

Root Cause

In CellTitleToolbarPart.setupChangeListeners(), event listeners for menu.onDidChange and toolbar.onDidChangeDropdownVisibility were being registered to the main disposable store using this._register() instead of the cell-specific disposable store.

This caused issues because:

  • These listeners are created during didRenderCell for each cell rendering cycle
  • When unrenderCell is called, it only clears this.cellDisposables
  • The listeners remained in the main disposable store, never getting cleaned up
  • Rapid cell creation/disposal cycles caused listener accumulation

Solution

Changed the event listener registration to use the cell-specific disposable store:

// Before (leaked)
this._register(menu.onDidChange(() => { ... }));
this._register(toolbar.onDidChangeDropdownVisibility(visible => { ... }));

// After (properly disposed)
this.cellDisposables.add(menu.onDidChange(() => { ... }));
this.cellDisposables.add(toolbar.onDidChangeDropdownVisibility(visible => { ... }));

This ensures the listeners are disposed when unrenderCell() calls this.cellDisposables.clear().

Testing

The fix targets the exact line mentioned in the error stack trace and follows the established pattern where cell-specific resources are managed by cellDisposables while component-level resources use the main disposable store.

Fixes #248531.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] cellPart toolbar leak Fix cellPart toolbar event listener memory leak Jul 2, 2025
@Copilot Copilot AI requested a review from Yoyokrazy July 2, 2025 22:06
Copilot finished work on behalf of Yoyokrazy July 2, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cellPart toolbar leak
3 participants