Memory leak or bad technique?
Hi. I've been noticing some strange memory profiles with (how I'm
using?) jQuery. I've tested this in IE6 and FF 2.0.0.6, and while IE6
behaves oddly, the "leak" appears to occur in FF. I suppose it's
possible that FF has a slow-release garbage collection scheme that
I've not let run long enough (longer than say, 15-20 min). This is on
Win XP Pro.
If this is not a leak, please help me understand what I'm doing to
cause it.
Example code:
<a href="#" id="clicktest">Toggle</a>
<div id="test">Lorem ipsum dolor sit.
</div>
<script language="javascript">
$(document).ready(function(){
$("#clicktest").click( function(){
$("#test").toggle();
});
});
</script>
Test:
Watch FF memory profile in Process Explorer. Note mem usage after each
step.
1. Start FF with about:blank, no add-ons, etc. 11.6M
2. Type file URL in address bar. 13.5M
3. Hit Enter and load page. 13.9M
4. Click link - toggle off. 13.9M
5. Click again - toggle on. 13.9M
6. Repeat 4&5 10 times. 14.7M
7. Repeat 4&5 25-30 times. 15-17.5M
8. Do nothing for a while. 15.5M
Keep toggling and you'll slowly grow the baseline.
Now, I changed the text in #test to just over 1M of paragraph text.
The numbers look like this (numbers in MB):
1. 11.6
2. 13.5
3. 16.9
4. 16.9
5. 17.0
6. 18.0
7. 18.1-20.4
8. Keep repeating 4&5 by holding Enter key. 19.1-22.6, and growing
9. Stop, wait, toggle a couple times. Drops to 21.2.
So, it seems that FF or jQ is not losing the div, since the baseline
grows by the same amount with short or huge data blocks (though it
starts higher with the 1M test).
Is my code wrong or ill-advised, or is there a leak under the covers
in jQ or FF?
Thanks! -bill