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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:33:32+00:00 2026-05-16T18:33:32+00:00

i was wondering if the following code would cause some problems like memory leak

  • 0

i was wondering if the following code would cause some problems like memory leak

<html>
<head>
    <script type='text/javascript' src='jquery-1.4.2.js'> </script>
    <script type="text/javascript">
        function a(){
            for(var i = 0; i < 50000; i++){
                $("#d").html("<span>" + i + "</span>");
            }
        }

    </script>
</head>
<body onload='a();'>
    <div id="d"></div>
</body>

  • 1 1 Answer
  • 2 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-16T18:33:32+00:00Added an answer on May 16, 2026 at 6:33 pm

    A simple span is being created here in each iteration. The html() function in jQuery runs an internal cleanData function that removes associated data and events from all contained nodes which isn’t the case here anyways.

    Then jQuery sets the innerHTML property to the passed in string which frees the existing elements. It’s up to the browser’s garbage collector to reclaim that memory whenever it can. There are no leaks in this code at all. Chrome is actually very fast in releasing that memory. I see a drop off from 2.421MB to 748KB mainly from the span elements being released in under 3 seconds.

    It does not wait for the page to unload to release this memory. These three snapshots were spaced apart by less than a second in which time almost 26000 HTMLElement objects were released from memory.

    Before opening the page

    alt text

    After opening page (23000 HTMLElement objects had already been released immediately, around 27000 were remaining)

    alt text

    Less than a second later (all 27000 objects except 1 were released)

    alt text

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

Sidebar

Related Questions

Just wondering, would the following code arrangement cause any issues when calling mysql_connect, i.e.:
I'd like to process some html code in javascript, to eliminate all extra whitespace,
I'm wondering why the following code doesn't work: String test = new String(new byte[]
So I am just wondering why the following code dosen't work. I am looking
The following code basically works as expected. However, to be paranoid, I was wondering,
I have the following code and was wondering why I am not allowed to
In the following code $j is the jquery object. I was wondering why I
I have the following code which is working, I was wondering if this can
I was wondering how can I allow NULL values in the following code below
I'm slowly understanding closures more and more, and the following code works. I'm wondering

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.