Skip to content

Commit

Permalink
Dispose Notebook DiffEditor ViewModels (#225369)
Browse files Browse the repository at this point in the history
* Dispose Notebook DiffEditor ViewModels

* Fix tests
  • Loading branch information
DonJayamanne authored Aug 12, 2024
1 parent ef656d3 commit b60fe00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { PixelRatio } from 'vs/base/browser/pixelRatio';
import { CellEditState, ICellOutputViewModel, IDisplayOutputLayoutUpdateRequest, IGenericCellViewModel, IInsetRenderOutput, INotebookEditorCreationOptions, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { DiffSide, DIFF_CELL_MARGIN, IDiffCellInfo, INotebookTextDiffEditor, INotebookDiffViewModel } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser';
import { Emitter, Event } from 'vs/base/common/event';
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { CellUri, INotebookDiffEditorModel, INotebookDiffResult, NOTEBOOK_DIFF_EDITOR_ID, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { URI } from 'vs/base/common/uri';
Expand Down Expand Up @@ -568,7 +568,9 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
NotebookTextDiffEditor.prettyChanges(this._model, diffResult.cellsDiff);
const { viewModels, firstChangeIndex } = NotebookTextDiffEditor.computeDiff(this.instantiationService, this.configurationService, this._model, this._eventDispatcher!, diffResult, this.fontInfo);

if (!this.notebookDiffViewModel.isEqual(viewModels)) {
if (this.notebookDiffViewModel.isEqual(viewModels)) {
dispose(viewModels);
} else {
this._originalWebview?.removeInsets([...this._originalWebview?.insetMapping.keys()]);
this._modifiedWebview?.removeInsets([...this._modifiedWebview?.insetMapping.keys()]);
this.notebookDiffViewModel.setViewModel(viewModels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class NotebookDiffViewModel extends Disposable implements INotebookDiffVi
super.dispose();
}
clear() {
this.disposables.clear();
dispose(Array.from(this.placeholderAndRelatedCells.keys()));
this.placeholderAndRelatedCells.clear();
dispose(this.originalCellViewModels);
Expand All @@ -33,8 +34,8 @@ export class NotebookDiffViewModel extends Disposable implements INotebookDiffVi
}

setViewModel(cellViewModels: DiffElementCellViewModelBase[]) {
this.disposables.clear();
const oldLength = this._items.length;
this.clear();
this._items.splice(0, oldLength);

let placeholder: DiffElementPlaceholderViewModel | undefined = undefined;
Expand Down

0 comments on commit b60fe00

Please sign in to comment.