Skip to content

fix: memory leak in folder configuration#279230

Merged
sandy081 merged 5 commits intomicrosoft:mainfrom
SimonSiefke:fix/memory-leak-folder-configuration
Jan 21, 2026
Merged

fix: memory leak in folder configuration#279230
sandy081 merged 5 commits intomicrosoft:mainfrom
SimonSiefke:fix/memory-leak-folder-configuration

Conversation

@SimonSiefke
Copy link
Contributor

Fixes some memory leaks in folder configuration / configuration service.

Issue one: Registering to global configuration service

Since there is only one global configuration service, registering a folder configuration to that class using this._register makes it so the class holds on to the folder configuration forever, since the global configuration service is never disposed.

private loadFolderConfigurations(folders: IWorkspaceFolder[]): Promise<ConfigurationModel[]> {
	/* ...*/
	let folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
	if (!folderConfiguration) {
		folderConfiguration = new FolderConfiguration(!this.initialized, folder, FOLDER_CONFIG_FOLDER_NAME, this.getWorkbenchState(), this.isWorkspaceTrusted, this.fileService, this.uriIdentityService, this.logService, this.configurationCache);
		this._register(folderConfiguration.onDidChange(() => this.onWorkspaceFolderConfigurationChanged(folder)));
		this.cachedFolderConfigs.set(folder.uri, this._register(folderConfiguration));
	}
	return folderConfiguration.loadConfiguration();
})]);
}

Fix

Registering all folder related disposables only to the map cachedFolderConfigs: Map<URI, FolderConfiguration>


Issue two: Resetting caches

This code resets the caches, but it doesn't dispose the values of the map.

// reset caches
this.cachedFolderConfigs = new ResourceMap<FolderConfiguration>();

Fix

Switching to a DisposableMap and making use of it's clearAndDisposeAll function.


Before

When executing a task 97 times, the number of functions/objects related to FolderConfiguration grows each time

Untitled (3)

After

When executing a task 97 times, while the number of various functions/objects still grows, it seems there are no more leaks related to FolderConfiguration

task quick-pick-run-task

@sandy081 sandy081 enabled auto-merge (squash) January 16, 2026 17:10
@vs-code-engineering vs-code-engineering bot added this to the January 2026 milestone Jan 16, 2026
@SimonSiefke
Copy link
Contributor Author

(updated branch to try to fix MacOS CI timeout)

@sandy081 sandy081 merged commit 51a7a0f into microsoft:main Jan 21, 2026
26 of 28 checks passed
@SimonSiefke SimonSiefke deleted the fix/memory-leak-folder-configuration branch January 21, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants