This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from ckeditor/t/ckeditor5/1341
Fix: There should be no memory leaks when the editor is created and destroyed (see ckeditor/ckeditor5#1341).
- Loading branch information
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<p> | ||
<button id="destroyEditor">Destroy editor</button> | ||
<button id="initEditor">Init editor</button> | ||
</p> | ||
|
||
<div id="editor"> | ||
<h2>Hello world!</h2> | ||
<p>This is an editor instance.</p> | ||
|
||
<img src="sample.jpg" /> | ||
</div> | ||
|
||
<style> | ||
.ck-editor { | ||
margin-top: 200px; | ||
margin-left: 100px; | ||
margin-bottom: 200px; | ||
width: 450px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals console:false, document, window */ | ||
|
||
import ClassicEditor from '../../src/classiceditor'; | ||
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset'; | ||
|
||
/* | ||
* Memory-leak safe version of classic editor manual test does not: | ||
* - define global variables (such as let editor; in main file scope) | ||
* - console.log() objects | ||
* - add event listeners with () => {} methods which reference other | ||
*/ | ||
function initEditor() { | ||
ClassicEditor | ||
.create( document.querySelector( '#editor' ), { | ||
plugins: [ ArticlePluginSet ], | ||
toolbar: { | ||
items: [ | ||
'heading', | ||
'|', | ||
'bold', | ||
'italic', | ||
'link', | ||
'bulletedList', | ||
'numberedList', | ||
'blockQuote', | ||
'insertTable', | ||
'mediaEmbed', | ||
'undo', | ||
'redo' | ||
] | ||
}, | ||
image: { | ||
toolbar: [ | ||
'imageStyle:full', | ||
'imageStyle:side', | ||
'|', | ||
'imageTextAlternative' | ||
] | ||
}, | ||
table: { | ||
contentToolbar: [ | ||
'tableColumn', | ||
'tableRow', | ||
'mergeTableCells' | ||
] | ||
} | ||
} ) | ||
.then( newEditor => { | ||
window.editor = newEditor; | ||
|
||
document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor ); | ||
} ) | ||
.catch( err => { | ||
console.error( err.stack ); | ||
} ); | ||
|
||
function destroyEditor() { | ||
window.editor.destroy().then( () => console.log( 'Editor was destroyed' ) ); | ||
window.editor = null; | ||
document.getElementById( 'destroyEditor' ).removeEventListener( 'click', destroyEditor ); | ||
} | ||
} | ||
|
||
document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
1. Open DevTools on Chrome. | ||
2. Go to Memory tab. | ||
3. Select "Heap snapshot" profiling type. | ||
4. Click "Collect Garbage" (trash icon) and "Clear all profiles" (don't go icon). | ||
5. Record heap snapshot ("Take heap snapshot" a record icon). | ||
6. Repeat multiple times: | ||
- click "Init editor", | ||
- wait to editor show up , | ||
- click "Destroy editor". | ||
7. Record heap snapshot again. | ||
8. Compare Snapshot 1 with Snapshot 2 and look for: | ||
- "detached" - HTML Elements/DOM nodes | ||
- "EventListener" - there should be only 1 | ||
- Any CKEditor5 classes instances like "Editor" or "LivePosition" | ||
|
||
## Notes: | ||
|
||
* Browser extensions might attach event listeners to the DOM so the safest way to run this test is by running Chrome from command line: | ||
|
||
``` | ||
google-chrome \ | ||
--enable-precise-memory-info \ | ||
--disable-extensions \ | ||
--disable-plugins \ | ||
--incognito \ | ||
http://localhost:8125 | ||
``` | ||
The above will run Chrome without extensions or plugins in incognito mode and open manual tests page. | ||
* Close any running Chrome instance beforehand because otherwise it will open a tab in currently opened Chrome (look for "Opening in existing browser session." in command line). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.