Skip to content

Commit

Permalink
Fixes #30189: Do not leak lines array in change listener closure (#30180
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alexdima committed Jul 6, 2017
1 parent 7c3bd02 commit 57583bf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/vs/workbench/services/textfile/common/textFileEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
this.setDirty(false);
}

this.toDispose.push(this.textEditorModel.onDidChangeContent(() => {
this.onModelContentChanged();
}));
// See https://github.com/Microsoft/vscode/issues/30189
// This code has been extracted to a different method because it caused a memory leak
// where `value` was captured in the content change listener closure scope.
this._installChangeContentListener();

return this;
}, error => {
Expand All @@ -459,6 +460,15 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return this.createTextEditorModelPromise;
}

private _installChangeContentListener(): void {
// See https://github.com/Microsoft/vscode/issues/30189
// This code has been extracted to a different method because it caused a memory leak
// where `value` was captured in the content change listener closure scope.
this.toDispose.push(this.textEditorModel.onDidChangeContent(() => {
this.onModelContentChanged();
}));
}

private doLoadBackup(backup: URI): TPromise<string> {
if (!backup) {
return TPromise.as(null);
Expand Down

0 comments on commit 57583bf

Please sign in to comment.