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

Commit fd18fb9

Browse files
authored
Merge pull request #459 from ckeditor/t/ckeditor5/1341
Fix: There should be no memory leaks when the editor is created and destroyed (see ckeditor/ckeditor5#1341).
2 parents 909e676 + f4d6223 commit fd18fb9

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

docs/_snippets/examples/bootstrap-ui-inner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class BootstrapEditorUI {
176176

177177
destroy() {
178178
this.view.editable.destroy();
179+
this.view.destroy();
179180
}
180181

181182
// This method activates Bold, Italic, Underline, Undo and Redo buttons in the toolbar.

src/toolbar/balloon/balloontoolbar.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,12 @@ export default class BalloonToolbar extends Plugin {
254254
* @inheritDoc
255255
*/
256256
destroy() {
257-
this._fireSelectionChangeDebounced.cancel();
258-
this.stopListening();
259257
super.destroy();
258+
259+
this.stopListening();
260+
this._fireSelectionChangeDebounced.cancel();
261+
this.toolbarView.destroy();
262+
this.focusTracker.destroy();
260263
}
261264

262265
/**

src/toolbar/block/blocktoolbar.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ export default class BlockToolbar extends Plugin {
150150
}
151151
}
152152

153+
/**
154+
* @inheritDoc
155+
*/
156+
destroy() {
157+
super.destroy();
158+
159+
// Destroy created UI components as they are not automatically destroyed (see ckeditor5#1341).
160+
this.panelView.destroy();
161+
this.buttonView.destroy();
162+
this.toolbarView.destroy();
163+
}
164+
153165
/**
154166
* Creates the {@link #toolbarView}.
155167
*

src/view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ export default class View {
493493
this.stopListening();
494494

495495
this._viewCollections.map( c => c.destroy() );
496+
497+
// Template isn't obligatory for views.
498+
if ( this.template && this.template._revertData ) {
499+
this.template.revert( this.element );
500+
}
496501
}
497502

498503
/**

tests/view.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ describe( 'View', () => {
325325
it( 'can be called multiple times', () => {
326326
expect( () => {
327327
view.destroy();
328+
view.destroy();
329+
view.destroy();
328330
} ).to.not.throw();
329331
} );
330332

0 commit comments

Comments
 (0)