Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#6388 closed bug

$.getJSON memory leak with JSONP even on success

Reported by: tarad10 Owned by: tarad10
Priority: undecided Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: JSONP Cc:
Blocked by: Blocking:


I am running $.getJSON inside an interval every 10 seconds. The script is polling the twitter search JSON API. It is grabbing the first 50 tweets based on a search query and dumping them into a div with the prepend() function.

The code works fine, but the $.getJSON function is leaking. I have spent a great deal of time trying to figure out why, but it seems like something is fundamentally wrong with the garbage collection.

My searching lead me to this site: http://neil.fraser.name/news/2009/07/27/. There is a mention of manually going into the script element and deleting all of the properties to force deallocation. I have implemented this into the uncompressed jQuery 1.4.2 include by adding these three lines directly after line 5027 (head.removeChild( script )):

for(var prop in script) { deletes script[prop]; }

This seems to help in that I can see at least some memory get freed up (before it was never going down), but it has not fixed the problem entirely. Perhaps I have implemented it in the wrong place, because it does not seem to delete all the properties.

I am not sure if this is due to running it within an interval or some other issue with my code, but I can't seem to figure out why it is leaking. I appreciate any help you can offer.

Change History (7)

comment:1 Changed 10 years ago by sharmila

I did face somewhat a similar issue. We do a getJSON call and construct a dynamic table and this is triggered at regular intervals.

It poses heavy memory usage each time when the call happens. Tried to free out and remove all the dom elements before reallocating. Still this doesn't help. Can someone give a clue on this of where is the memory issue actually happening in IE.

comment:2 Changed 10 years ago by snover

Owner: set to tarad10
Priority: undecided
Status: newpending

Could you please provide a test case demonstrating this issue?

comment:3 Changed 10 years ago by trac-o-bot

Status: pendingclosed

Automatically closed due to 14 days of inactivity.

comment:4 Changed 10 years ago by anonymous

Still having this problem as well!

comment:5 Changed 10 years ago by snover

comment:6 Changed 9 years ago by piuccio@…

I know that it's quite old, but the leak happens on 1.6.1 as well.

Test case is very easy:

    <title>Detect leak</title>
    <script type="text/javascript" src="jquery-1.6.1.js"></script>
  <script type="text/javascript">
    var doReload = function (iteration) {
      iteration -= 1;
      if (iteration < 0) {

        url : "http://search.twitter.com/search.json?q=jquery&rpp=1",
        dataType : "jsnop"

      window.setTimeout(function () {
      }, 500);

    // Start the test

Open process explorer and look at the memory allocation. You'll clearly see a leak.

As a matter of facts, the leaks happens in IE every time you add and remove a script tag from the head. You'll get the same leak even if you don't use jQuery but add the script manually.

Hope you guys find a way to dispose a script tag correctly.

comment:7 Changed 9 years ago by piuccio@…

BTW this is a duplicate of #8205

Note: See TracTickets for help on using tickets.