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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:50:16+00:00 2026-05-25T19:50:16+00:00

This maybe a bit of a silly question. I’m assuming that the garbage collector

  • 0

This maybe a bit of a silly question. I’m assuming that the garbage collector disposes of any dangling variables after a function ends execution, but I was wondering if this also applies to DOM fragments.

If I create a DOM fragment or any unattached node for that matter, will the garbage collector delete it after the function has finished execution?

//would this create a memory leak?
setInterval(function exampleScope() {
    var unusedDiv = document.createElement('div');
}, 10);

I know this example is useless but its the simplest form of the pattern I’m worried about. I just want to know I’m doing the right thing. I’ve been hard at work building a very high performance JavaScript game engine, Red Locomotive. I don’t want to add any memory leaks.

  • 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-25T19:50:16+00:00Added an answer on May 25, 2026 at 7:50 pm

    Well, it’s not 100% conclusive but I made a quick JSFiddle to experiment with this. This is a tight loop that runs your code above 100000000 times. Using the Chrome Task Manager memory usage jumped from 47.9MB to 130MB and stayed fairly constant until completed, where it dropped down to 60MB ish.

    http://jsfiddle.net/u7yPM/

    This suggests that the DOM nodes are definitely being garbage collected, else the memory usage would continue increasing for the whole run of the test.

    EDIT: I ran this on Chrome 14.

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

Sidebar

Related Questions

Ok, so this may be a bit of a silly question, and there's certainly
Ok so this maybe a simple/silly question but I don't know so here goes:
This is maybe an oblique question: I'm writing an emulator in VB6 (silly me).
Maybe my doubt is a bit silly. But I couldn't find any answer similar
This may be a silly question but should I use the 32 bit or
This may be a silly question, but still I'm a bit curious... Recently I
This maybe a bit of a 'wide' question, but am putting together a brief
This may be a bit of a silly question and I might also have
This is a bit of a silly question but I don't know how to
This may be a bit silly question, but I just started doing pretty things

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.