Re: What's faster, saving an HTML DOM node as a variable, or using getElementById?




Laurent Bugnion wrote:
Hi,

scriptguru@xxxxxxxxx wrote:

Be careful with cashing node references. getElementById can be slightly
slower but also it is always safer.
For example we saved some node reference in variable. Then we modified
document.body.innerHTML. Reference we saved is dead now.

Val Polyakh

Actually, it's worse than just dead, it's a zombie, a reference to an
object which won't be garbage-collected unless you set it explicitly to
null. That could be the source of many a memory leak.

That's not a memory leak, it's just poor coding - the memory will be
released when the page is replaced. Obviously if you are going to
store references you need to manage them.


--
Rob

.



Relevant Pages

  • Re: Looping-related Memory Leak
    ... memory leak / balloon for reasons I cannot figure out. ... end of the loop. ... reference count never reaches zero, and they remain alive until the ... the generational collector doesn't break cycles that involve ...
    (comp.lang.python)
  • Event handling, DOM, closures and memory leaks (again)
    ... But I needed to store DOM elements and can't solve it ... method solution to cleanup memory leak problems. ... return handler; ... creating a circular reference. ...
    (comp.lang.javascript)
  • Re: Memory leak in ruby code
    ... a method that cleared the reference. ... No different to a memory leak in a non-garbage collected language. ... static data member or in a dynamic data member (instance ... obj could be reclaimed after doSomeWork(assuming the stack ref is the ...
    (comp.lang.ruby)
  • Re: Garbage collector bug
    ... > analogy of subscribing a mailing list, in perfectly working world, yes I ... > need to inform list server that I'm dead or I have moved so it can remove me ... > I've lost the reference. ... it *is* accessible - by the delegate. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: copy contructor
    ... "" and forget to put it in DESTROY, whereas my approach would look like: ... the memory leak isn't the worst problem. ... That's indeed a minor problem. ... Inside-Out object work because every the memory address of every reference ...
    (comp.lang.perl.misc)