Bug Tracker

Ticket #8205 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 4 years ago by danheberden

  • Owner set to John Cena
  • Status changed from new to pending
  • Component changed from unfiled to ajax

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?

comment:2 Changed 4 years ago by danheberden

  • Status changed from pending to closed
  • Resolution set to worksforme

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/

comment:3 Changed 4 years ago by John Cena

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.

comment:4 Changed 4 years ago by John Cena

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

comment:5 Changed 4 years ago by anonymous

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.

comment:6 Changed 4 years ago by danheberden

  • Status changed from closed to reopened
  • Resolution worksforme deleted

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!

comment:7 Changed 4 years ago by dmethvin

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.

comment:8 Changed 4 years ago by danheberden

  • Status changed from reopened to open

comment:9 Changed 4 years ago by danheberden

  • Priority changed from undecided to low

comment:10 Changed 4 years ago by John Cena

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.

comment:11 Changed 3 years ago by rtabor

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.

comment:12 follow-up: ↓ 13 Changed 3 years ago by rwaldron

I fail to see how this is a "memory leak" -- If anything, it's poor browser performance.

comment:13 in reply to: ↑ 12 Changed 3 years ago by rtabor

Replying to 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.

comment:14 Changed 3 years ago by jaubourg

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.

comment:15 Changed 3 years ago by jaubourg

  • Status changed from open to closed
  • Resolution set to fixed

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

comment:16 Changed 3 years ago by dmethvin

  • Milestone changed from 1.next to 1.8
Note: See TracTickets for help on using tickets.