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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:36:44+00:00 2026-05-11T18:36:44+00:00

What is JavaScript garbage collection? What’s important for a web programmer to understand about

  • 0

What is JavaScript garbage collection? What’s important for a web programmer to understand about JavaScript garbage collection, in order to write better code?

  • 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-11T18:36:44+00:00Added an answer on May 11, 2026 at 6:36 pm

    Eric Lippert wrote a detailed blog post about this subject a while back (additionally comparing it to VBScript). More accurately, he wrote about JScript, which is Microsoft’s own implementation of ECMAScript, although very similar to JavaScript. I would imagine that you can assume the vast majority of behaviour would be the same for the JavaScript engine of Internet Explorer. Of course, the implementation will vary from browser to browser, though I suspect you could take a number of the common principles and apply them to other browsers.

    Quoted from that page:

    JScript uses a nongenerational
    mark-and-sweep garbage collector. It
    works like this:

    • Every variable which is “in scope”
      is called a “scavenger”. A scavenger
      may refer to a number, an object, a
      string, whatever. We maintain a list
      of scavengers — variables are moved
      on to the scav list when they come
      into scope and off the scav list when
      they go out of scope.

    • Every now and then the garbage
      collector runs. First it puts a
      “mark” on every object, variable,
      string, etc – all the memory tracked
      by the GC. (JScript uses the VARIANT
      data structure internally and there
      are plenty of extra unused bits in
      that structure, so we just set one of
      them.)

    • Second, it clears the mark on the
      scavengers and the transitive closure
      of scavenger references. So if a
      scavenger object references a
      nonscavenger object then we clear the
      bits on the nonscavenger, and on
      everything that it refers to. (I am
      using the word “closure” in a
      different sense than in my earlier
      post.)

    • At this point we know that all the
      memory still marked is allocated
      memory which cannot be reached by any
      path from any in-scope variable. All
      of those objects are instructed to
      tear themselves down, which destroys
      any circular references.

    The main purpose of garbage collection is to allow the programmer not to worry about memory management of the objects they create and use, though of course there’s no avoiding it sometimes – it is always beneficial to have at least a rough idea of how garbage collection works.

    Historical note: an earlier revision of the answer had an incorrect reference to the delete operator. In JavaScript the delete operator removes a property from an object, and is wholly different to delete in C/C++.

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

Sidebar

Ask A Question

Stats

  • Questions 143k
  • Answers 143k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer On updating which folder does SVN give this error message?… May 12, 2026 at 8:24 am
  • Editorial Team
    Editorial Team added an answer Turns out that the answer to this involves CR2008's new… May 12, 2026 at 8:24 am
  • Editorial Team
    Editorial Team added an answer function go() { var url = '<%= ApplicationPathUtils.getApplicationPath(pageContext) + "/Weather"… May 12, 2026 at 8:24 am

Related Questions

What is JavaScript garbage collection? What's important for a web programmer to understand about
While browsing with Chrome, I noticed that it responds extremely fast (in comparison with
I have a page in my application that refreshes some content (a list of
I'm having an issue with rails involving javascript. Basically, I have the following code:
This are my first two lines: <?php header('Content-Type: application/x-javascript'); And it gives me the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.