Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:03:20+00:00 2026-05-13T14:03:20+00:00

I have hunted around for answer to this one, and though have found related

  • 0

I have hunted around for answer to this one, and though have found related quesions, I couldn’t quite find an exact match for this.

I have a fairly large app which is supposed to load pages into divs in another page using the jQuery.load() method. The problem I have is that when loading the same page over and over again into the same div, I see the memory of the browser increase substantially (memory leak). If I call $(“*”).unbind, I of course do not see a leak, but then everything has been reset, so this isn’t reallya fix. The following code example reproduces this problem:

Test1.htm

<head>
   <title></title>
    <script type="text/javascript" language="javascript" src="Scripts/jquery-1.3.2.js"></script>
        <script type="text/javascript" language="javascript">
        <!--
            var i = 0;
        $(document).ready(function() {
            $("#btn").click(
                function() {
                    i++;
                    $("#Test1").load("Test2.htm", null, function() {
                        //$(document).trigger("test");
                    })
                    $("#count").html(i);
                });
        });
    //-->
    </script>
</head>
<body>
    <img id="btn" src="someimage.png" />
    <h3>We are loading Test2.htm into below div</h3>
    <div>
        Count loads =<span id="count">0</span>
    </div>
    <div id="Test1" style="border-style:solid">EMPTY</div>
</body>

Test2.htm = any old html page..

If you load Test1.htm and click the button mutliple times, you’ll notice the browser memory steadily increasing. I believe the problem is that the loaded js and DOM elements are never set for garbage collection. In my real world system I have tried removing (elem.remove() or .empty()) the loaded elements, but this doens’t really fix the problem. I also have many js files loaded using “src”, which I replaced with $.getScript, this seems to have had made a small improvement. These are all workarounds thought, and I wanted to find a real solution for this problem. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:03:21+00:00Added an answer on May 13, 2026 at 2:03 pm

    Edit: update due to more info provided about test2.htm (the page being loaded)

    Original answer (for historical purposes): I don’t actually see any leaks in the code/markup you have provided – is it possible the leak is in Test2.htm (which you haven’t provided the code/markup for)?

    New answer:

    I would suggest that it it probably due to either multiple loads of jQuery, or other scripts you have in test2.htm.

    Assuming jQuery does not leak by simply instantiating and then nullifying jQuery and $, loading multiple times will keep at least 2 copies of jQuery in memory. When loaded, jQuery keeps a backup of any previous versions of $ and jQuery in _$ and _jQuery – so you are going to have at least 2 copies of jQuery loaded when you use load() multiple times.

    The above assumption is most likely not correct however – there is every chance that jQuery has leaks even if you “unload” it by setting $,jQuery,_$ and _jQuery to null – it’s not really intended to be loaded multiple times like that (however I’m sure that they allow it intentionally, so you can use noConflict() to load and use two different versions of jQuery if necessary).

    You can add a “selector” to a load URL. For example:

    $("#Test1").load("Test2.htm body", null, function() { 
      //callback does nothing
    });
    //or
    $("#Test1").load("Test2.htm div#the_Div_I_Want", null, function() { 
      //callback does nothing
    });
    

    I would suggest doing this if you are not interested in any scripts in the ajax result, or alternatively if you do want scripts, you’d need to choose a selector to disable only certain elements/scripts, e.g.

    /* load with selector "all elements except scripts whose
       src attribute ends in 'jquery.js'" */
    $("#Test1").load("Test2.htm :not(script[src$='jquery.js'])", null, function() { 
      //callback does nothing
    });
    

    Also of note is that if you leave out the “data” argument (you have it as null), and provide a function as the second argument, jQuery will correctly determine that the second argument is the callback, so

    $("#Test1").load("Test2.htm :not(script[src$='jquery.js'])", function() { 
      //callback does nothing
    });
    

    is acceptible

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have hunted around and have not found any methods to do what I
I've hunted around for this, and I am sure that I am just missing
I'm working on this page http://seriesaddict.fr/Hunted/772 and I have this: .ficheserie_casting img.style_img, img.style_img a:hover
Couldn't find Submission without an ID This problem has haunted me for last few
I apologize if this has been asked here - I've hunted around here and
have written this little class, which generates a UUID every time an object of
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have been using the python logging module for quite some time now, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.