0

What happens when a cloned node is not attached to any DOM. Suppose I have a JavaScript code Clone a DOM element every time it's method is called.I need this object temporarily, I don't need to add it to DOM component. But I am worried if it creates performance issue in client side so I am wondering what happens to the object cloned by javascript.

Declan Cook
  • 6,066
  • 2
  • 35
  • 52
prakashpoudel
  • 565
  • 2
  • 9
  • 25
  • You can either delete it manually, or let [garbage collection](http://stackoverflow.com/questions/864516/what-is-javascript-garbage-collection) take care of it... – Joseph Silber Feb 23 '12 at 20:04
  • If it's referenced in JavaScript, it's a good idea to nullify the references if you're supporting older versions of IE. Pretty sure they had some memory leaks in that respect. –  Feb 23 '12 at 20:05

2 Answers2

0

It depends on how you are assigning the clone, but it's possible they could accumulate in memory.

No code = no idea.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
0

As soon as the JavaScript Engine detects you are done with that object its garbage collector will clean it up for you. As long as the object isn't in the global scope or is able to be referenced it will be cleaned on a garbage collector pass.

Declan Cook
  • 6,066
  • 2
  • 35
  • 52
  • If I haven't assign cloned object to any reference variable does it treats like global variable scope. for e.g in my code below – prakashpoudel Feb 24 '12 at 15:56