[thelist] JS memory leak detection?
VOLKAN ÖZÇELİK
volkan.ozcelik at gmail.com
Sun Oct 23 05:09:14 CDT 2005
> so, i play with JS a lot, and i have a pretty good feel for writing
> scripts, but i'm not so good with tracking down memory leaks...
>
As Jeff has said "welcome to the dark side" :) The next stage is
washing your dishes with ajax (okay yet another bad joke).
>
> i've read these two articles, and am having a little trouble
> determining if and how they can be applied:
>
> http://novemberborn.net/javascript/event-cache
> http://laurens.vd.oever.nl/weblog/items2005/closures/
>
The memory leakage issue is not a myth. IE does experience it, but you
will hardly recognize it if you are not attaching several hundereds of
events on window.onload (and most of them create circular-references
to each other.)
imho, you usually do not generate a circular reference to a DOM node like
myParagraph.darling=anotherParagraph;
anotherParagraph.fiance=myParagraph;
I don't generally create relations like this (to avoid a duel between
another paragraph's fiance and darling -- okay no more jokes :) - I
have a flu and my body is a bit over-heated, I guess that's because of
it).
In short, I did not observe any circular references in your code.
> essentially, i am looking for some JS genius-level feedback on the
> modified code i am using here and what i can do to optimize it:
> http://algonquinstudios.com/js/flyoutnav.js
>
I had also implemented a registy mechanism somewhat similar to the
referenced article:
http://www.sarmal.com/sardalya/api/Object.aspx?id=EventRegistry
and I use it none the less to be on the safe side (actually my cross
browser EventHandler object
http://www.sarmal.com/sardalya/api/Object.aspx?id=EventHandler
handles the registry issues on the back end, so I do not need to think
about it any more. Actually I have almost forgotten about it until
this post)
---
My humble suggestion:
Optimization without observation is of no use. Open your task manager.
Without closing the browser, try refreshing the page several thousand
times (or use a meta refresh). note the delta in CPU an ram
utilization.
If after half an hour your CPU has reached near 100%, then you do have
a leakage problem and need to implement a event registry of some sort.
HTH,
--
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
+> My projects/studies/trials/errors : http://www.sarmal.com/
More information about the thelist
mailing list