Skip to content

Commit d92c78a

Browse files
committed
Merge pull request #3797 from Microsoft/disposeSnapshot-1.5
Port PR 3689 into release 1.5
2 parents 331b63d + e190761 commit d92c78a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/services/services.ts

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ module 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 {
@@ -1873,6 +1876,16 @@ module ts {
18731876
// after incremental parsing nameTable might not be up-to-date
18741877
// drop it so it can be lazily recreated later
18751878
newSourceFile.nameTable = undefined;
1879+
1880+
// dispose all resources held by old script snapshot
1881+
if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) {
1882+
if (sourceFile.scriptSnapshot.dispose) {
1883+
sourceFile.scriptSnapshot.dispose();
1884+
}
1885+
1886+
sourceFile.scriptSnapshot = undefined;
1887+
}
1888+
18761889
return newSourceFile;
18771890
}
18781891
}

src/services/shims.ts

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module 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 {
@@ -242,6 +245,14 @@ module ts {
242245
return createTextChangeRange(
243246
createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength);
244247
}
248+
249+
public dispose(): void {
250+
// if scriptSnapshotShim is a COM object then property check becomes method call with no arguments
251+
// 'in' does not have this effect
252+
if ("dispose" in this.scriptSnapshotShim) {
253+
this.scriptSnapshotShim.dispose();
254+
}
255+
}
245256
}
246257

247258
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {

0 commit comments

Comments
 (0)