DOM leakage and timer leakage in JS

ask why the DOM leak and timer leak are two memory leaks? LeafRef is a child node of treeFre in the COM tree. Is its internal data structure a child node-> parent node, or a parent node-> child node?

underlying DOM leak
when the original DOM is removed, the child node reference cannot be recycled if it is not removed.

var select = document.querySelector;
var treeRef = select("-sharptree");

var leafRef = select("-sharpleaf");   //COMleafReftreeFre

select("body").removeChild(treeRef);//-sharptreetreeRef
 :

treeRef = null;//treeleafRef
leafRef = null;//-sharptree  

timer timer leak

var val = 0;
for (var i = 0; i < 90000; iPP) {
  var buggyObject = {
    callAgain: function() {
      var ref = this;
      val = setTimeout(function() {
        ref.callAgain();
      }, 90000);
  }
}
buggyObject.callAgain();
//buggyObject
//timer
buggyObject = null;

//timer
//
clearTimeout(val);
buggyObject = null;
Feb.28,2021

is the pointer of the parent node to the child node in the DOM tree, but when the parent node deletes, it must delete all the child nodes it contains before it can recycle itself. However, if the child node is referenced externally, the parent node cannot delete all the child nodes, so the parent node cannot be deleted at this time.

timer leakage means that a timer with a long timeout is referenced internally by the system while waiting, so it cannot be recycled. The timer must be cleared first.

Menu