Procházet zdrojové kódy

Merge pull request #1635 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 před 6 roky
rodič
revize
2a1f3772cd

+ 3 - 1
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -351,7 +351,9 @@ export default class DataController {
 	/**
 	 * Removes all event listeners set by the DataController.
 	 */
-	destroy() {}
+	destroy() {
+		this.stopListening();
+	}
 
 	/**
 	 * Checks if all provided root names are existing editor roots.

+ 8 - 0
packages/ckeditor5-engine/src/view/document.js

@@ -122,6 +122,14 @@ export default class Document {
 	}
 
 	/**
+	 * Destroys this instance. Makes sure that all observers are destroyed and listeners removed.
+	 */
+	destroy() {
+		this.roots.map( root => root.destroy() );
+		this.stopListening();
+	}
+
+	/**
 	 * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
 	 *
 	 * @protected

+ 4 - 0
packages/ckeditor5-engine/src/view/editableelement.js

@@ -77,6 +77,10 @@ export default class EditableElement extends ContainerElement {
 		}
 	}
 
+	destroy() {
+		this.stopListening();
+	}
+
 	/**
 	 * Returns document associated with the editable.
 	 *

+ 2 - 0
packages/ckeditor5-engine/src/view/view.js

@@ -398,6 +398,8 @@ export default class View {
 			observer.destroy();
 		}
 
+		this.document.destroy();
+
 		this.stopListening();
 	}