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 6357263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:07:53+00:00 2026-05-24T23:07:53+00:00

I am working on a large enterprise application with a LOT of JavaScript. Enough

  • 0

I am working on a large enterprise application with a LOT of JavaScript. Enough that I can’t possibly go through and fix all the small circular references that have been created over its past 5 years of development. While researching solutions I came across this small jQuery hack/patch:

http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/

and decided to try it. Amazingly, it works! sIEVE shows no leaks in the places I had previously identified them and the iexplore task is maintaining a more manageable memory footprint.

My question is, why does this work? jQuery.remove calls .removeChild, which should get rid of the element, but apparently does not. The patch instead appends the target element onto a new garbage collector div, which it then clears. Why does the patch method of removal completely free up the memory but jQuery’s remove function does not? I’m hoping to understand why this works in order to possibly improve the solution before I check it in to the larger application.

  • 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-24T23:07:54+00:00Added an answer on May 24, 2026 at 11:07 pm

    This is the .remove method in the current jQuery release (1.6.2). Notice that it calls .cleanData:

    // keepData is for internal use only--do not document
        remove: function( selector, keepData ) {
            for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
                if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
                    if ( !keepData && elem.nodeType === 1 ) {
                        jQuery.cleanData( elem.getElementsByTagName("*") );
                        jQuery.cleanData( [ elem ] );
                    }
    
                    if ( elem.parentNode ) {
                        elem.parentNode.removeChild( elem );
                    }
                }
            }
    
            return this;
        },
    

    And the .cleanData method which it calls, which mentions a ticket number and allegedly prevents that horrible leak (according to one of the comments):

    cleanData: function( elems ) {
            var data, id, cache = jQuery.cache, internalKey = jQuery.expando, special = jQuery.event.special,
                deleteExpando = jQuery.support.deleteExpando;
    
            for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
                if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
                    continue;
                }
    
                id = elem[ jQuery.expando ];
    
                if ( id ) {
                    data = cache[ id ] && cache[ id ][ internalKey ];
    
                    if ( data && data.events ) {
                        for ( var type in data.events ) {
                            if ( special[ type ] ) {
                                jQuery.event.remove( elem, type );
    
                            // This is a shortcut to avoid jQuery.event.remove's overhead
                            } else {
                                jQuery.removeEvent( elem, type, data.handle );
                            }
                        }
    
                        // Null the DOM reference to avoid IE6/7/8 leak (#7054)
                        if ( data.handle ) {
                            data.handle.elem = null;
                        }
                    }
    
                    if ( deleteExpando ) {
                        delete elem[ jQuery.expando ];
    
                    } else if ( elem.removeAttribute ) {
                        elem.removeAttribute( jQuery.expando );
                    }
    
                    delete cache[ id ];
                }
            }
        }
    

    And here is the ticket mentioned in the comment. Apparently it was fixed eight months ago:

    http://bugs.jquery.com/ticket/7054#comment:10

    According to Dave Methvin the solution seems to be to Ensure that the DOM element ref in an event handler is removed by cleanData to avoid an IE6/7/8 memory leak.

    In other words, set references to DOM elements within event handlers to null otherwise some awesome browsers, without mentioning any names cough IE cough will leak memory.

    discardElement (from your link) inserts the element into a container, and then empties the container, thereby nullifying any references to that element.

    With that in mind, I would suggest upgrading jQuery. The article you point to is from 2009, and two years is roughly equivalent to four-hundred-zillion man hours of jQuery development time.

    Finally, here is some interesting (and ridiculously long) reading on leak patterns in Internet Explorer:

    • Understanding and Solving Internet Explorer Leak Patterns
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with large numbers that I can't have rounded off. Using Lua's standard
I am working within a enterprise architecture that is processing a large amount of
I am working on the architecture of a large enterprise application which will be
We are working with large amounts of data, all tagged in UTC (in Java).
I am working with a large Java web application from a commercial vendor. I've
I'm working on a large c++ system that is has been in development for
I am working on an enterprise system that will utilise a RESTful web service
I'm working on a user facing django application for an enterprise solution. Currently, users
I'm working on a large php site that currently does not use any framework.
I'm a freelancer and prefer working on large projects all by my own self.

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.