Skip to content

Commit ba3d2db

Browse files
committed
dispose script snapshots from the old source file
1 parent 32a040b commit ba3d2db

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/services/services.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ namespace ts {
9191
* not happen and the entire document will be re - parsed.
9292
*/
9393
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange;
94+
95+
/** Releases all resources held by this script snapshot */
96+
dispose?(): void;
9497
}
9598

9699
export module ScriptSnapshot {
@@ -1863,6 +1866,16 @@ namespace ts {
18631866
// after incremental parsing nameTable might not be up-to-date
18641867
// drop it so it can be lazily recreated later
18651868
newSourceFile.nameTable = undefined;
1869+
1870+
// dispose all resources held by old script snapshot
1871+
if (sourceFile.scriptSnapshot) {
1872+
if (sourceFile.scriptSnapshot.dispose) {
1873+
sourceFile.scriptSnapshot.dispose();
1874+
}
1875+
1876+
sourceFile.scriptSnapshot = undefined;
1877+
}
1878+
18661879
return newSourceFile;
18671880
}
18681881
}

src/services/shims.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace ts {
3434
* Or undefined value if there was no change.
3535
*/
3636
getChangeRange(oldSnapshot: ScriptSnapshotShim): string;
37+
38+
/** Releases all resources held by this script snapshot */
39+
dispose?(): void;
3740
}
3841

3942
export interface Logger {
@@ -243,6 +246,12 @@ namespace ts {
243246
return createTextChangeRange(
244247
createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength);
245248
}
249+
250+
public dispose(): void {
251+
if ("dispose" in this.scriptSnapshotShim) {
252+
this.scriptSnapshotShim.dispose();
253+
}
254+
}
246255
}
247256

248257
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {

0 commit comments

Comments
 (0)