Skip to content

Commit 4405725

Browse files
authored
fix(language-service): address potential memory leak during project creation
This addresses a potential memory leak in plugin-factory.ts. The require call inside the create function reloads the entire language service module for every new project, which is inefficient and could be a cause of the memory leak during branch switching. This ensures the module is loaded only once and the same instance is shared across all projects.
1 parent 033ea75 commit 4405725

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/language-service/plugin-factory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export const factory: ts.server.PluginModuleFactory = (tsModule): PluginModule =
2121

2222
return {
2323
create(info: ts.server.PluginCreateInfo): NgLanguageService {
24-
// Use a module name based import path to allow it to be marked external.
25-
plugin = require(`@angular/language-service/bundles/language-service.js`)(tsModule);
24+
plugin ??= require(`@angular/language-service/bundles/language-service.js`)(tsModule);
2625
return plugin.create(info);
2726
},
2827
getExternalFiles(project: ts.server.Project): string[] {

vscode-ng-language-service/server/src/session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,11 @@ export class Session {
706706
this.triggerDiagnostics(event.data.openFiles, event.eventName);
707707
break;
708708
case ts.server.ProjectLanguageServiceStateEvent:
709+
this.logger.info(
710+
`Project language service state changed for ${event.data.project.getProjectName()}. Enabled: ${
711+
event.data.languageServiceEnabled
712+
}`,
713+
);
709714
this.connection.sendNotification(ProjectLanguageService, {
710715
projectName: event.data.project.getProjectName(),
711716
languageServiceEnabled: event.data.languageServiceEnabled,
@@ -969,6 +974,7 @@ export class Session {
969974
if (!filePath) {
970975
return;
971976
}
977+
this.logger.info(`Closing file: ${filePath}`);
972978
this.openFiles.delete(filePath);
973979
this.projectService.closeClientFile(filePath);
974980
}

0 commit comments

Comments
 (0)