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

Memory leaks - nullifying DOM elements with event handlers attached is not sufficient #184

Open
Jemt opened this issue Apr 3, 2023 · 1 comment

Comments

@Jemt
Copy link
Owner

Jemt commented Apr 3, 2023

Fit.UI relies on the browser's Garbage Collector to reclaim memory - we do that by nullifying all variables within a control. But to my surprise this does not guarantee that the browser cleans up event handlers registered on DOM elements. Chrome reports these handlers as detached:

image

Clicking the highlighted link takes us to:

input.onchange = function() // OnKeyUp does not catch changes by mouse (e.g. paste or moving selected text)

Other event handlers within Fit.Controls.Input has also been marked as the cause of retained references.

We need to find all event handlers and make sure they are removed when Dispose() is called.
It works - it has been tested with the following event handlers in the Input control: input.onkeyup, input.onchange, and "paste" on me.GetDomElement().

Search for (regex): [a-zA-Z0-9].on.+ =
Search for: Fit.Events.AddHandler(
Search for: addEventListener(
Search for: attachEvent(

Perform not only these searches in Fit.UI but also all projects built on Fit.UI.
With every single match we must ensure registered event handlers are removed when a component is disposed.

Also see #155 and #172

@FlowIT-JIT
Copy link
Collaborator

These lines keep a reference to controls even when disposed, which should be avoided, even though they are internally destroyed. Consider using a string reference instead such as me.GetId().

Fit._internal.ContextMenu.Current = me;

emojiPanel._associatedFitUiControl = me;

Fit._internal.Controls.Input.ActiveEditorForDialog = me; // Editor instance is needed when OnHide event is fired for dialog on global CKEditor instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants