Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14106 closed bug (notabug)

Ajax memory leak

Reported by: roberto@… 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 6 years ago by roberto@…

the full code:

<html>
<head>
<script language="javascript" src="jquery-2.0.3.js"></script> 
<script>
function READ(a,b,c){
	delete a,b,c,this;
	setTimeout( UPDATE ,0);
}
function READ_err(a,b,c){
	delete a,b,c,this;
	setTimeout( UPDATE ,0);
}
function UPDATE(ar){
	$.ajax({
		type	: "GET",
		dataType: 'json',
		cache	: false,
		url	: "same_page.php"
	}).done(READ).fail(READ_err);
}

</script>
</head>
<body>
<script>UPDATE();</script>
</body>
</html>

comment:2 Changed 6 years ago by roberto@…

source at jsFiddle http://jsfiddle.net/C5jfb/

comment:3 Changed 6 years ago by roberto@…

setting cache : true, estabilized at ~ 50MB, but my code isn't cacheable... maybe it's a problem on cache code?

comment:4 Changed 6 years ago by timmywil

Resolution: notabug
Status: newclosed

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 6 years ago by roberto@…

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 6 years ago by roberto@…

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 6 years ago by dmethvin

I modified your test case only slightly and had it run every second rather than the setTimeout(,0)

http://jsfiddle.net/C5jfb/1/

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.

http://i.imgur.com/Vcu8Out.png

comment:8 Changed 6 years ago by dmethvin

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 6 years ago by roberto@…

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

Note: See TracTickets for help on using tickets.