tweakpane icon indicating copy to clipboard operation
tweakpane copied to clipboard

Memory leak caused by detached nodes after calling Pane.dispose()

Open michaeldll opened this issue 1 year ago • 4 comments

Hello there, thank you for your work. Been using your library for a long time.

However, I'm observing a significant memory leak caused by detached Blade DOM elements, even after calling dispose() on their parent Pane:

Screenshot 2024-12-05 at 17 04 29

I followed the instructions here: https://tweakpane.github.io/docs/misc/#disposing.

Reproducing should be fairly simple:

  1. Start a Chrome Detached Nodes memory trace
  2. Call dispose() on a parent Pane
  3. End the trace

Let me know if I'm missing something.

Thanks again.

michaeldll avatar Dec 05 '24 16:12 michaeldll

Do you clear the variable for the pane? For example:

window.pane = new Pane();
window.pane.dispose();

this code still retains references to detached nodes because window.pane isn't cleared. To avoid that, set it to null after disposing of the pane:

window.pane = new Pane();
window.pane.dispose();

window.pane = null;

A minimal reproduction environment will help in investigating the issue. You can use tools like CodeSandbox to set up the environment.

cocopon avatar Jan 09 '25 09:01 cocopon

Are event handlers also removed when pane.dispose() is called?

2mik avatar Feb 26 '25 07:02 2mik

window.pane = new Pane();
window.pane.dispose();
window.pane = null;

What if we don't need to delete the pane itself, but need to add new blades?

2mik avatar Feb 28 '25 11:02 2mik

Hey there, sorry for being away for so long. I don't think I was clearing the variable at the time of posting this, thanks for the advice. I'll re-test this again when I have the time !

michaeldll avatar Oct 15 '25 10:10 michaeldll