Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #459 from ckeditor/t/ckeditor5/1341
Browse files Browse the repository at this point in the history
Fix: There should be no memory leaks when the editor is created and destroyed (see ckeditor/ckeditor5#1341).
  • Loading branch information
oleq authored Jan 22, 2019
2 parents 909e676 + f4d6223 commit fd18fb9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/_snippets/examples/bootstrap-ui-inner.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class BootstrapEditorUI {

destroy() {
this.view.editable.destroy();
this.view.destroy();
}

// This method activates Bold, Italic, Underline, Undo and Redo buttons in the toolbar.
Expand Down
7 changes: 5 additions & 2 deletions src/toolbar/balloon/balloontoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ export default class BalloonToolbar extends Plugin {
* @inheritDoc
*/
destroy() {
this._fireSelectionChangeDebounced.cancel();
this.stopListening();
super.destroy();

this.stopListening();
this._fireSelectionChangeDebounced.cancel();
this.toolbarView.destroy();
this.focusTracker.destroy();
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/toolbar/block/blocktoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ export default class BlockToolbar extends Plugin {
}
}

/**
* @inheritDoc
*/
destroy() {
super.destroy();

// Destroy created UI components as they are not automatically destroyed (see ckeditor5#1341).
this.panelView.destroy();
this.buttonView.destroy();
this.toolbarView.destroy();
}

/**
* Creates the {@link #toolbarView}.
*
Expand Down
5 changes: 5 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ export default class View {
this.stopListening();

this._viewCollections.map( c => c.destroy() );

// Template isn't obligatory for views.
if ( this.template && this.template._revertData ) {
this.template.revert( this.element );
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ describe( 'View', () => {
it( 'can be called multiple times', () => {
expect( () => {
view.destroy();
view.destroy();
view.destroy();
} ).to.not.throw();
} );

Expand Down

0 comments on commit fd18fb9

Please sign in to comment.