瀏覽代碼

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).
Aleksander Nowodzinski 6 年之前
父節點
當前提交
13ea1bae4b

+ 1 - 0
packages/ckeditor5-ui/docs/_snippets/examples/bootstrap-ui-inner.js

@@ -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.

+ 5 - 2
packages/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js

@@ -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();
 	}
 
 	/**

+ 12 - 0
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -151,6 +151,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}.
 	 *
 	 * @private

+ 5 - 0
packages/ckeditor5-ui/src/view.js

@@ -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 );
+		}
 	}
 
 	/**

+ 2 - 0
packages/ckeditor5-ui/tests/view.js

@@ -325,6 +325,8 @@ describe( 'View', () => {
 		it( 'can be called multiple times', () => {
 			expect( () => {
 				view.destroy();
+				view.destroy();
+				view.destroy();
 			} ).to.not.throw();
 		} );