question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`resize` event listeners for subfolders outlive destruction of the gui

See original GitHub issue

I noticed an apparent memory leak in an application that was repeatedly updating a dat.GUI in a loop, and I believe it may be due to the ever-increasing number of resize event handlers added to the window. Obviously creating and destroying guis in a tight loop is not a great idea, but I’d still like to at least make sure the program doesn’t leak memory.

To reproduce, using the latest dat.gui.js, simply run in the console:

for (let i = 0; i < 1000; i++) {
    gui = new dat.GUI();
    let f = gui.addFolder("hello");
    gui.destroy();
}

then inspect getEventListeners(window).resize and observe that 1000 new elements have been added. Calling gui.removeFolder(f) appears to make no difference. It seems like f.destroy() should fix the problem, since it unbinds the resize listener, but that actually fails:

for (let i = 0; i < 1000; i++) {
    gui = new dat.GUI();
    let f = gui.addFolder("hello");
    f.destroy();
    gui.destroy();
}
dat.gui.min.js:13 Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at e.destroy (http://127.0.0.1:5010/js/dat.gui.min.js:13:45356)
    at <anonymous>:4:4

Can you give me any advice? Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
technbuzzcommented, Dec 19, 2019

My mistake, somehow the prototype of gui.removeFolder was modified accidently. All the events are properly removed now with gui.destroy()

0reactions
technbuzzcommented, Dec 17, 2019

I am using the very latest version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Window: resize event - Web APIs | MDN
The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble.
Read more >
javascript on resize Code Example - Code Grepper
javascript resize event ; 1. window.resize = event => { ; 2. // Code here ; 3. }; ...
Read more >
JavaScript window resize event - Stack Overflow
Best practice is to add to the resize event, rather than replace it: window.addEventListener('resize', function(event) { ... }, true);.
Read more >
https://raw.githubusercontent.com/Esri/jsapi-resou...
toJson(): any; /** Fired when a credential object is destroyed. */ on(type: "destroy", listener: (event: { target: Credential }) => void): esri.
Read more >
The Project window - Unity - Manual
Individual Assets are shown in the right hand panel as icons that indicate their type (for example, script, material, sub-folder). To resize the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found