-
Notifications
You must be signed in to change notification settings - Fork 786
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 leak - Detached HTML elements #713
Comments
I've created a pull request #715 that solves this issue (at least in my test-case). Hope it helps! |
@jf-m Thanks again! |
Hello. Is there any chances that this issue could have been the source of a memory problem causing crashes on Safari iOS ? |
Hi @bpeab, I would say the answer of your question highly depends on your implementation of interact.js. This means that the impact of this bug on the performances within your application, (and thus, the possibility of a crash) depends on what is linked to that detached HTML element. In my case, I've been able to detect this issue because I use interact.js on a fairly big SPA application that uses VueJS. The detached HTML element had some listeners linked to it that referenced one of my heaviest (memory-wise) vueJS component. Also, this leak happens only when you destroy and re-create the interactable element. So if you don't do it in your application, then this issue is not linked to your crash. The best way to know the answer would be to use Chrome Heap Snapshots on your application and find out how many memory the detached element takes in your case, and see how it stacks over the time. Even if you are not facing any crashes on Chrome, it would help you anyway I'd say. |
Expected behavior
I'm using interactjs in a SPA where I need to destroy/recreate several times an interact element.
When I need to destroy an interactable element I do the following:
This call should be enough for the GC to collect and garbage all the retained memory by interactjs.
Actual behavior
In the Heap Snapshots of Chrome there is a Detached HTMLElement stored and never released by
interactjs
every time Iunset
.The HTMLElement is referenced in the object
Interactable
inside thethis._latestPointer
variablethis._latestPointer.eventTarget
.Solving proposition
For the moment, here is what happens inside the
unset
method:interact.js/packages/core/scope.ts
Line 93 in 587eb94
I think we should call a new
destroy
method from interactionInside the
destroy
method ofinteraction
, it needs to clear up the memory like so :I've tried this solution and its working, the GC can collect and garbage.
I'm not proposing a Pull Request because maybe
unset
is not the right place for cleaning the memory, and maybe a newdestroy
ordetach
method should be provided byscope
.I let you guys decide.
System configuration
interact.js version: 1.4.0-RC.13
Browser name and version: Chrome
Operating System: MacOS
The text was updated successfully, but these errors were encountered: