Skip to main content

Bug Tracker

Side navigation

#14106 closed bug (notabug)

Opened July 06, 2013 04:45AM UTC

Closed July 06, 2013 02:36PM UTC

Last modified July 06, 2013 08:16PM UTC

Ajax memory leak

Reported by: roberto@spadim.com.br 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

Attachments (0)
Change History (9)

Changed July 06, 2013 05:03AM UTC by roberto@spadim.com.br comment:1

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>

Changed July 06, 2013 05:42AM UTC by roberto@spadim.com.br comment:2

source at jsFiddle

http://jsfiddle.net/C5jfb/

Changed July 06, 2013 07:40AM UTC by roberto@spadim.com.br comment:3

setting cache : true,

estabilized at ~ 50MB, but my code isn't cacheable...

maybe it's a problem on cache code?

Changed July 06, 2013 02:36PM UTC by timmywil comment:4

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.

Changed July 06, 2013 07:09PM UTC by roberto@spadim.com.br comment:5

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

Changed July 06, 2013 07:13PM UTC by roberto@spadim.com.br comment:6

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

Changed July 06, 2013 08:03PM UTC by dmethvin comment:7

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

Changed July 06, 2013 08:07PM UTC by dmethvin comment:8

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.

Changed July 06, 2013 08:16PM UTC by roberto@spadim.com.br comment:9

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