Skip to content

Commit f79f5bb

Browse files
committed
Merge pull request #3331 from Microsoft/clean_hostCache
perf: clean hostCache to avoid extending lifetime of script snapshots
2 parents 9d736bc + 22e493d commit f79f5bb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/services/services.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,10 @@ module ts {
24752475
}
24762476
}
24772477

2478+
// hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point.
2479+
// It needs to be cleared to allow all collected snapshots to be released
2480+
hostCache = undefined;
2481+
24782482
program = newProgram;
24792483

24802484
// Make sure all the nodes in the program are both bound, and have their parent
@@ -2483,6 +2487,7 @@ module ts {
24832487
return;
24842488

24852489
function getOrCreateSourceFile(fileName: string): SourceFile {
2490+
Debug.assert(hostCache !== undefined);
24862491
// The program is asking for this file, check first if the host can locate it.
24872492
// If the host can not locate the file, then it does not exist. return undefined
24882493
// to the program to allow reporting of errors for missing files.

0 commit comments

Comments
 (0)