Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's make sure we destroy all keystroke handlers #6561

Closed
oleq opened this issue Apr 6, 2020 · 2 comments · Fixed by #10803
Closed

Let's make sure we destroy all keystroke handlers #6561

oleq opened this issue Apr 6, 2020 · 2 comments · Fixed by #10803
Labels
squad:core Issue to be handled by the Core team. status:discussion type:task This issue reports a chore (non-production change) and other types of "todos".

Comments

@oleq
Copy link
Member

oleq commented Apr 6, 2020

Provide a description of the task

A follow-up of #6087. Precisely ckeditor/ckeditor5-ui#552 (comment).

See how many instances are created:

14 results - 14 files

font  src/ui/colortableview.js:
  77: 		this.keystrokes = new KeystrokeHandler();

🖼 image  src/imagetextalternative/ui/textalternativeformview.js:
  55: 		this.keystrokes = new KeystrokeHandler();

🔗 link  src/ui/linkactionsview.js:
  54: 		this.keystrokes = new KeystrokeHandler();

🔗 link  src/ui/linkformview.js:
  64: 		this.keystrokes = new KeystrokeHandler();

media-embed  src/ui/mediaformview.js:
  58: 		this.keystrokes = new KeystrokeHandler();

table  src/tablecellproperties/ui/tablecellpropertiesview.js:
  186: 		this.keystrokes = new KeystrokeHandler();

table  src/tableproperties/ui/tablepropertiesview.js:
  161: 		this.keystrokes = new KeystrokeHandler();

🕹 ui  src/focuscycler.js:
  42:  *		const keystrokeHandler = new KeystrokeHandler();

🕹 ui  src/colorgrid/colorgridview.js:
  72: 		this.keystrokes = new KeystrokeHandler();

🕹 ui  src/dropdown/dropdownview.js:
  176: 		this.keystrokes = new KeystrokeHandler();

🕹 ui  src/dropdown/button/splitbuttonview.js:
  97: 		this.keystrokes = new KeystrokeHandler();

🕹 ui  src/list/listview.js:
  52: 		this.keystrokes = new KeystrokeHandler();

🕹 ui  src/toolbar/toolbarview.js:
  100: 		this.keystrokes = new KeystrokeHandler();

utils  src/keystrokehandler.js:
  29:  *				this.keystrokes = new KeystrokeHandler();

and so few are destroyed 😛

1 result - 1 file

core  src/editor/editor.js:
  269: 				this.keystrokes.destroy();

To stay on the safe side, let's balance that.

@oleq oleq added type:task This issue reports a chore (non-production change) and other types of "todos". intro Good first ticket. labels Apr 6, 2020
@oleq oleq added this to the iteration 31 milestone Apr 6, 2020
@Reinmar
Copy link
Member

Reinmar commented Apr 20, 2020

I'm not sure about this. Is it really necessary? In which cases we are forced to do that?

Once a UI component is destroyed it's also detached from the DOM (or should be). If the listener was added to the element that was removed from the DOM, then removing this listener is not necessary.

How would a case in which we really need to destroy a keystroke handler look? Do we have such cases?

@Reinmar Reinmar added status:discussion and removed intro Good first ticket. labels Apr 20, 2020
@Reinmar Reinmar modified the milestones: iteration 31, next Apr 20, 2020
@jodator
Copy link
Contributor

jodator commented Apr 20, 2020

If the listener was added to the element that was removed from the DOM, then removing this listener is not necessary.

I don't recall if it did cause problems in #1341. However, we still haven't addressed new issues (#5954) and such DOM references might cause problems. Any listener attached to DOM might hold reference to the editor (by scope).

But, in most cases, removing it from DOM should be safe - so proper UI destroy() should cover that.

@pomek pomek modified the milestones: next, nice-to-have Nov 10, 2020
Reinmar added a commit that referenced this issue Nov 5, 2021
Internal: Made sure `KeystrokeHandler` and `FocusTracker` instances are destroyed across the UI in the project to avoid memory leaks. Closes #10749. Closes #6561.

Tests (ckeditor5): Added a semi-automated manual test to investigate memory leaks in the editor (see #10749).
@Reinmar Reinmar modified the milestones: nice-to-have, iteration 49 Nov 5, 2021
@Reinmar Reinmar added the squad:core Issue to be handled by the Core team. label Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:core Issue to be handled by the Core team. status:discussion type:task This issue reports a chore (non-production change) and other types of "todos".
Projects
None yet
4 participants