Side navigation
#8205 closed bug (fixed)
Opened February 08, 2011 06:21AM UTC
Closed May 16, 2012 06:04PM UTC
Last modified May 16, 2012 06:11PM UTC
JSONP random result is causing memory leak in IE8
Reported by: | John Cena | Owned by: | John Cena |
---|---|---|---|
Priority: | low | Milestone: | 1.8 |
Component: | ajax | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Dear Sir/Madam,
I found there is memory leak when I call cross browser domain (jsonp) repeatedly every seconds. Here is the sample code that I used to replicate the bugs (I used yui url as a sample since they produce random result).
<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script>
function run()
{
$.getJSON("http://yuilibrary.com/gallery/api/random?callback=?",
function(data) {
document.getElementById("span1").innerText = data.modules[0].summary;
});
setTimeout("run()",1000);
}
</script>
</head>
<body onload="run();">
<span id="span1"></span>
</body>
</html>
After I run several minutes, the memory will be getting bigger until it reach "Out Of Memory" browser alert. I have tested using jquery 1.42, 1.44 and 1.5 and those version still have the memory leak problem. I used this simple sample, therefore the memory increment progress is very slow (but is still getting bigger) and I will get memory increment progress faster if I get huge random data in the respond. I used the latest version of IE8 browser to replicate this problem.
Please let me know either I need to add additional code in jquery-1.5.js or in that code.
Thanks
Attachments (0)
Change History (16)
Changed February 08, 2011 09:14AM UTC by comment:1
component: | unfiled → ajax |
---|---|
owner: | → John Cena |
status: | new → pending |
Changed February 08, 2011 09:28AM UTC by comment:2
resolution: | → worksforme |
---|---|
status: | pending → closed |
Ran this in IE8 and had no memory problems. Perhaps something isn't quite right in the rest of your code?
Test ran: http://jsfiddle.net/danheberden/jU2VG/2/
Changed February 08, 2011 09:52AM UTC by comment:3
Hi danheberden
Yes, your code seems similar with mine which are still producing memory leak in IE8 (8.0.6001.18999IC). You can check it from Task Manager -> Resource Monitor -> check the Memory section, especially Commit(KB). The memory usage can be growth to 500MB until more than 1GB after several hours for executing that simple code. It will be stopped until it reach Max (Out of Memory). I believe there is some part in jquery which is need to be fixed/enhanced. Please let me know which part that need to be fixed/added and I will do the same thing at my end. Thanks.
Changed February 08, 2011 09:55AM UTC by comment:4
Hi danheberden,
Please don't close this issue too fast as I am still getting the same problem. You need to check carefully the memory growth through Resource Monitor (Memory Commit section), it grows slowly since it is very simple sample program. It is very critical since my program receive huge jsonp respond which can caused browser crashed after run it several hours.
Thanks
Changed February 08, 2011 10:30AM UTC by comment:5
Hi danheberden,
To replicate this issue, you need to copy paste my code and run it in fresh IE8 browser (close existing IE browser and open the new one), example it starts with 13,528KB then it grows to 13,538...13,600..13,689..etc. Imagine if the jsonp data is very huge, then the memory leak will growth faster. Thanks.
Changed February 08, 2011 04:51PM UTC by comment:6
resolution: | worksforme |
---|---|
status: | closed → reopened |
John, can you try it with this test? http://jsfiddle.net/danheberden/jU2VG/5/show/
the one that i gave you would keep appending elements, which would of course increase memory (my bad!) - i'm gonna run it longer this time for myself, i had ran it for about 15 minutes last night and it was actually at less amount of ram than at start :/
I'll mark it pending since Dave's seemed to reproduce it too. Thanks for your diligence!
Changed February 08, 2011 05:40PM UTC by comment:7
Yes, I can reproduce this. In a quick read-through of the new ajax script.js transport it looks like it is doing all the right things, including nulling out the handlers and removing the script element.
Changed February 08, 2011 05:43PM UTC by comment:8
status: | reopened → open |
---|
Changed February 08, 2011 05:53PM UTC by comment:9
priority: | undecided → low |
---|
Changed February 09, 2011 01:47AM UTC by comment:10
Hi guys, thanks for doing this. Please let me know once you have found the solution since it is quite critical to have my application reliable to run in a very long time. Otherwise, the browser IE8 is keep crashing.
Changed December 07, 2011 03:06AM UTC by comment:11
I also see a memory leak with JQuery ajax jsonp requests. I have observed the leak in IE, FireFox and Google Chrome. I would like to request that the priority of this bug be increased.
A reduced test case is provided at http://jsfiddle.net/G2kq8/3/show. This sample code makes repeated calls to the //jsfiddle.net/echo/jsonp echo api to demonstrate the memory leak that occurs when you repeatedly load large chunks of data with jsonp in JQuery. To isolate the problem, the code doesn’t process the data it receives; it just repeatedly requests the data and updates a counter on the HTML page. This test case is similar to http://jsfiddle.net/danheberden/jU2VG/5/, but demonstrates the problem a little more dramatically by loading a larger data block in each request.
The browser’s memory usage will continually increase while this example is run. The memory will not be freed until the page is refreshed. If allowed to run continuously all of the memory on the PC is consumed by the browser in a matter of hours. The browser will periodically perform garbage collection, and the memory usage can be seen to decrease occasionally, but it always decreases to a memory level higher than that achieved at the last garbage collection.
This example has been demonstrated to leak in Internet Explorer 8 (Specifically 8.0.6001.18702), Firefox 8.0 and Chrome 15.0.874.121. Firefox was run in safe mode, IE was run with third party extensions disabled, and chrome was run with no extension. Most of my testing was done with Firefox. The leak appeared to be most pronounced in Firefox.
This example has been demonstrated to leak using jQuery 1.7.1, jQuery (edge), and jQuery 1.2.6.
My Operating System is Microsoft Windows XP Professional, Version 2002, Service Pack 3.
Changed December 07, 2011 03:15AM UTC by comment:12
I fail to see how this is a "memory leak" -- If anything, it's poor browser performance.
Changed December 07, 2011 03:40AM UTC by comment:13
Replying to [comment:12 rwaldron]:
I fail to see how this is a "memory leak" -- If anything, it's poor browser performance.
Thanks for your quick response. I consider this a "memory leak" because the memory is never recovered until the page is refreshed. If you stop the test, garbage collection will never reduce the browser's memory usage.
Semantics aside, do you really not consider it a problem that the current version of jQuery will cause all major browsers to exhaust all of system memory in a matter of hours when fetching large chunks of data with jsonp? If the repetition rate is reduced to once a second (which seems more than reasonable) the browser will still chew up all available memory overnight. This is the problem I am currently dealing with in the product I am developing.
Changed December 07, 2011 09:28AM UTC by comment:14
Well, it's two-fold really.
On one hand, I can see memory usage grow in FF 8.0.1 on a widows 7 machine when requests are NOT running (yes, you read this correctly).
On the other hand, we should look if there wouldn't be some help we could give browsers to properly garbage collect but I suspect that the issue lies with the returned Promise and associated scopes.
Given how transports are already cleared and how callbacks lists also are, I don't feel that optimistic, especially in IE.
Changed May 16, 2012 06:04PM UTC by comment:15
resolution: | → fixed |
---|---|
status: | open → closed |
Fixes #8205. Mitigates memory usage by recycling jsonp callback names the safest possible way (no kittens were harmed in the making of this). Doesn't even try to delete window properties (would necessitate a try/catch for IE which makes the cost in size prohibitive). Unit tests added.
Changeset: 8ebb2f4793d2c464888b5f0dba97fb5c9d0c9541
Changed May 16, 2012 06:11PM UTC by comment:16
milestone: | 1.next → 1.8 |
---|
Thanks for helping to test out jQuery. Typically I'd ask you to make a test case on jsfiddle, but there are some concerns with your testing code that might be part of your issue.
Here is a better test case that doesn't use the eval form of setTimeout: http://jsfiddle.net/danheberden/jU2VG/
How's that running for you in ie8?