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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:57:03+00:00 2026-06-12T11:57:03+00:00

I keep reading the same thing: Storing property values directly on DOM elements is

  • 0

I keep reading the same thing:

“Storing property values directly on DOM elements is risky because of possible memory leaks.”

But can someone explain these risks in more detail?

  • 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-12T11:57:04+00:00Added an answer on June 12, 2026 at 11:57 am

    (By attribute, I assume you are referring to properties on DOM elements.)

    Are custom properties on DOM elements safe?

    Some browsers have not cleaned up DOM elements very well when destroyed. References to other elements, the same element, or large sets of data were therefore retained, causing leaks. I believe this is largely resolved in newer browsers.

    In any case, storing small amounts of data on an element is innocuous, and can be very convenient, so take that warning with a grain of salt.


    Is using jQuery’s .data() a safe alternative?

    Not especially. Storing data using jQuery’s custom data store has its own potential for memory leaks, and unfortunately they don’t merely affect old browsers.

    In order to avoid leaks, you’d need to be absolutely certain you clean an element’s .data() when destroying an element. This is automatic when you use jQuery to destroy the element, but if you don’t, you’ll have memory leaks that affect every browser.


    What are some examples that can cause leaks?

    Let’s say that there’s a bunch of .data() linked to the #foo element. If we use jQuery methods to remove the element, we’re safe:

    $("#foo").remove(); // associated .data() will be cleaned automatically
    

    But if we do this, we have a cross-browser compatible leak:

    var foo = document.getElementById("foo");
    foo.parentNode.removeChild(foo);
    

    Or if #foo is a descendant of some other element whose content is being cleared without jQuery, it would be the same issue.

    otherElement.innerHTML = "";
    

    In both cases, jQuery was not used to remove #foo, so its .data() is permanently disassociated from the element, and our application has a leak.


    So if I never use the DOM API directly, I’m safe?

    You’re safer, but another way this can happen is if we load more than one DOM manipulation library. Consider that jQuery helps us do this with the following code:

    var $jq = jQuery.noConflict();
    

    Now we can allow $ to refer to prototypejs or mootools, and jQuery is referenced by $jq.

    The trouble is that those other libraries will not clean up data that was set by jQuery, because they don’t know about it.

    So if jQuery has some data on #foo, and mootools is used to destroy that element, we have our memory leak.


    What if I never use .data() in jQuery? Does that make me safe?

    Sadly, no. jQuery uses the same .data() mechanism to store other data, like event handlers. Therefore even if you never make a call to .data() to associate some custom data with an element, you can still have memory leaks caused by the examples above.

    Most of the time you may not notice the leaks, but depending on the nature of the code, they can eventually grow large enough to be a problem.

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

Sidebar

Related Questions

I keep reading that in order for one to perform integer/floating point division on
I keep reading that object-oriented programming can basically be done in any programming language,
I keep reading how everyone states to return a XmlDocument when you want to
We keep reading about how to use 'readResolve()' to ensure singleness in case of
I used the XMLReader format: XmlReader xmlReader = XmlReader.Create(batch.xml); while (xmlReader.Read()) { //Keep reading
In my reading on dynamic and static typing, I keep coming up against the
Possible Duplicate: Pointer to local variable Can a local variable's memory be accessed outside
I'm reading some data from memory, and this area of memory is in Unicode.
I keep getting this error Error in readPNG(destfile) : libpng error: PLTE: CRC error
Keep running into When using the multi-mapping APIs ensure you set the splitOn param

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.