dataarts / dat.gui

Lightweight controller library for JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Destroy listeners

mcfly10 opened this issue · comments

After I make datGui.destroy() it still scans for binded objects

let node = {};
let value = 123;
Object.defineProperty(node, "value", {
    get: function () {
        console.log("Scan value");
        return value;
    },
    set: function (v) {
        value = v;
    },
});

// ...

datGui.add(node, "value").name("Value").listen();

// ...

datGui.destroy();

After removing console still writes "Scan value".
It s not critical for static properties, but for getters it could slow the performanse.

on my side it seem ok, did you check in your debug listener
image

For me gui.destroy(); perfectly works. It traverses through all the folder/nested folders and look for controls and unregister them.

I'm not able to reproduce this sorry. I think it was fixed in a previous version. If you still have the problem, please provide a demo so we can debug. Thanks!

I'm having issue cleaning up listeners as well. (on 0.7.7)

I used the test code below

      function testDAT() {
        var FizzyText = function() {
        this.message = 'dat.gui';
        this.speed = 0.8;
        this.displayOutline = false;
        }

        for (let n=0; n<100; n++ ){
          var text = new FizzyText();
          var gui = new dat.GUI();
          gui.add(text, 'message');
          gui.add(text, 'speed', -5, 5);
          gui.add(text, 'displayOutline');
          gui.updateDisplay();
          gui.destroy();
        }
      };

      var FizzyText2 = function() {
        this.message = 'dat.gui';
        this.speed = 0.8;
        this.displayOutline = false;
        }

      function testDAT2() {
        for (let n=0; n<100; n++ ){
          var text = new FizzyText2();
          var gui = new dat.GUI();
          gui.add(text, 'message');
          gui.add(text, 'speed', -5, 5);
          gui.add(text, 'displayOutline');
          gui.updateDisplay();
          gui.destroy();
        }
      };

and my Performance Log in Chrome DevTools is showing
image

where the Nodes and Listeners remain high (>2K) after GC.

However, I can't seem to find any of these listeners when I look at EventListener of the elements in DOM Tree.

Is the Listening trace in Performance not what I think it is or are the listeners not getting unergistered properly by destroy?