`resize` event listeners for subfolders outlive destruction of the gui
See original GitHub issueI 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:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My mistake, somehow the prototype of
gui.removeFolder
was modified accidently. All the events are properly removed now withgui.destroy()
I am using the very latest version.