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

  • Home
  • SEARCH
  • 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 8658859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:52:06+00:00 2026-06-12T15:52:06+00:00

I recently read in this tutorial that certain jQuery leaks are trackable through the

  • 0

I recently read in this tutorial that certain jQuery leaks are trackable through the $.cache variable, and you should always check its size, if it’s too large, you’re doing something wrong.

Well, how large is too large? Is there a way to inspect a variable to see how much memory it is eating up?

I’m working on a website that caches 210 objects only by loading the homepage. Is that too much? I would appreciate a thorough explanation about the issue here.

  • 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-06-12T15:52:07+00:00Added an answer on June 12, 2026 at 3:52 pm

    $.cache‘s size at face value does not tell anything about memory leaks. It could be very small and still have a memory leak, or it could be very large and not have any memory leak.

    If you know you have 10 event listeners bound with jQuery on the page at a time, and yet $.cache has entries for more, then you know you are leaking.

    A huge memory saver is to use event delegation rather than attaching event listeners to each individual element.

    Say:

    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
    

    $("li").on( "click", fn ) would attach 3 individual event handlers (more, if you have more li’s of course), whereas $("ul").on( "click", "li", fn) would attach just one regardless of how many li-elements you have and yet have the same result.


    Example of leak:

    $("button").click( function() {
        $("#target")[0].innerHTML = "";
        $("<div>").appendTo( $("#target")).click( $.noop );
        $("#log").text( Object.keys( $.cache ).length );
    });​
    

    http://jsfiddle.net/SGZW4/1/

    Reason being that .innerHTML is used, which is not part of jQuery so it cannot do clean up.

    Fix is to use jQuery method for the same:

    $("button").click( function() {
        $("#target").html("");
        $("<div>").appendTo( $("#target")).click( $.noop );
        $("#log").text( Object.keys( $.cache ).length );
    });​
    

    http://jsfiddle.net/SGZW4/2/

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

Sidebar

Related Questions

Recently I read a book( CleanCode ) in this book, FUNCTION SHOULD DO ONE
I recently read through Code Complete, and it recommends that I create a project
Recently, I read this article: http://download.oracle.com/javase/tutorial/extra/generics/wildcards.html My question is, instead of creating a method
I recently read a jQuery tutorial about best practices. I usually run all my
I recently read this blog entry by Hadi Hariri: That dreaded M in ASP.NET
I recently read this list and I noticed that almost everything I studied from
I recently read a blog in Nodejitsu and I am wondering how this piece
I recently read a post online about rotating text with css. This appealed to
I recently read in a presentation on Scribd that Facebook had benchmarked a variety
I recently read that getters/setters are evil and I have to say it makes

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.