Skip to content

Commit 22d3894

Browse files
committed
Merge pull request microsoft#3877 from Microsoft/port-3797-to-master
Port PR 3797 to master
2 parents 32a040b + 93e5cae commit 22d3894

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-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 !== newSourceFile && 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: 11 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,14 @@ namespace ts {
243246
return createTextChangeRange(
244247
createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength);
245248
}
249+
250+
public dispose(): void {
251+
// if scriptSnapshotShim is a COM object then property check becomes method call with no arguments
252+
// 'in' does not have this effect
253+
if ("dispose" in this.scriptSnapshotShim) {
254+
this.scriptSnapshotShim.dispose();
255+
}
256+
}
246257
}
247258

248259
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {

0 commit comments

Comments
 (0)