memory leaks - Javascript remove all descendants of a div/node -


i've been working on memory leaks in javascript time now. i've come point feel solution @ least of leaks remove given div , of it's descendants. meaning children, grandchildren, etc.

now i'm under impression need recursive function if want this, i'm still new javascript. don't know if recursion works same way in javascript i'm used to.

i'm open ideas on how such thing, perhaps i'm way off mark idea of recursion.

this destroy node , children:

var _dummynode; var destroy = function(node){    if(!_dummynode) _dummynode = document.createelement('div');    _dummynode.appendchild(node.parentnode.removechild(node));    _dummynode.innerhtml = ""; } destroy(nodetodestroy); 

it creates dummy div never gets appended doc doesn't show. node removed parent , appended dummy. it's wiped out innerhtml.

however - fail if still have variable references nodes. should use ajax library , use appropriate addeventlistener attach events. shouldn't do:

<div onclick="myfunction();">click me</div> 

because it's not separation of concerns, it's hard maintain, doesn't pass events, , can attach 1 method. , if way need own garbage collecting.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -