#14106 closed bug (notabug)
Ajax memory leak
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 2.0.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
hi guys i'm using jquery 2.0.3 and running a retry script that runs forever, it's: <script> function READ(a,b,c){
delete a,b,c; setTimeout( UPDATE ,30);
} function READ_err(a,b,c){
delete a,b,c; setTimeout( UPDATE ,30);
} function UPDATE(){
$.ajax({
type : "GET", dataType: 'json', cache : false, url : "some page"
}).done(READ).fail(READ_err);
} </script> onload: UPDATE();
after 10 minutes, my chrome (version 27) get near to 80MB of ram, when i start it was at 13MB
any help is wellcome
Change History (9)
comment:1 Changed 10 years ago by
comment:3 Changed 10 years ago by
setting cache : true, estabilized at ~ 50MB, but my code isn't cacheable... maybe it's a problem on cache code?
comment:4 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
You are running a loop that builds up local variables in the stack. If it stopped at 50mb, my guess is that is because some browsers probably cap the amount of memory you can use on one stack.
delete a,b,c,this;
has no effect.
comment:5 Changed 10 years ago by
any idea how to avoid memory in this stack? since it's async call i think the a,b,c,this is only local to success function, not? maybe another varible is being lost and causing the memory leak?
any idea how to rewrite this function with "javascript good pratices"? i'm a bit lost why this leak memory
comment:6 Changed 10 years ago by
if you run the code it's always return to READ_err since it's not a json, it's not a problem for me, me problem is why i have a memory leak? setTimeout execute externally from READs functions, and UPDATE is a global function, in other words, i have no new function / variables being created, but memory consume is increasing
comment:7 Changed 10 years ago by
I modified your test case only slightly and had it run every second rather than the setTimeout(,0)
I'm not seeing any leak. Here is a Chrome memory trace, you can see it collects garbage occasionally and returns to the baseline memory usage.
comment:8 Changed 10 years ago by
I should also mention that I used an Incognito tab for the testing. If you have Chrome extensions installed they may be leaking memory and there's nothing jQuery can do about that.
comment:9 Changed 10 years ago by
using ctrl shift i, in chrome you don't see the leak press shift esc and see the memory consume in task monitor, it consume a lot and don't stop, garbage colector execute collection, but no memory was 'removed' from chrome, i'm running more than 1 hour and it's > 130MB now
the full code: