Skip to content

Conversation

@SimonSiefke
Copy link
Contributor

Fixes a memory leak in call stack widget.

Details

In setFrames, a new disposable seems to be registered each time using this._register:

/** Replaces the call frames display in the view. */
public setFrames(frames: AnyStackFrame[]): void {
	// cancel any existing load
	this.currentFramesDs.clear();
	this.cts = new CancellationTokenSource();
	this._register(toDisposable(() => this.cts!.dispose(true)));

	this.list.splice(0, this.list.length, this.mapFrames(frames));
}

E.g. when setFrames is called 10 times, 10 disposables would be registered to the class.

Fix

By registering the disposable to currentFramesDs instead of using this._register, there will be at most one of this disposable registered. Similar to how mapFrames also uses currentFramesDs instead of this._register.

/** Replaces the call frames display in the view. */
public setFrames(frames: AnyStackFrame[]): void {
	// cancel any existing load
	this.currentFramesDs.clear();
	const cts = new CancellationTokenSource();
	this.currentFramesDs.add(toDisposable(() => cts.dispose(true)));
	this.cts = cts;

	this.list.splice(0, this.list.length, this.mapFrames(frames));


}

Before

When opening the test view using the test-provider extension sample and running tests 97 times, the number of functions in CallStackWidget.setFrames seems to grow by 1 each time:

Untitled (2)

After

When opening the test view using the test-provider extension sample and running tests 97 times, while the number of some functions still grows, the number of functions in CallStackWidget.setFrames stays constant:

test-view

Copy link
Member

@connor4312 connor4312 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@connor4312 connor4312 enabled auto-merge (squash) January 7, 2026 16:12
@vs-code-engineering vs-code-engineering bot added this to the December 2025 milestone Jan 7, 2026
@connor4312 connor4312 merged commit dc17837 into microsoft:main Jan 7, 2026
17 checks passed
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.

5 participants