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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:13:16+00:00 2026-05-24T11:13:16+00:00

I have a case where I have a variable in my JavaScript that will

  • 0

I have a case where I have a variable in my JavaScript that will be used to store the reference to several instances of a class. The class creates a div based window, kind of like a lightbox, and then when I call the class’ removeWindow method, the div window elements are removed from the DOM. So a sequence might be like this:

var divWindow = null;
divWindow = new DivWindowClass(...);
/* do some stuff with the window */
divWindow.removeWindow();

Later on in the code I create a window again with different content, but I also want to be able to check if the divWindow variable is referencing anything.

Is it correct to just do:

divWindow.removeWindow();
divWindow = null;

if (divWindow == null) { /* etc. */ }

/* later in the code */
divWindow = new DivWindowClass(...); /* with different content than first one */

or does that cause memory issues with the JavaScript garbage collection? If I set divWindow to null, will that signal to the garbage collection to gather up my object and get rid of it, or is there something else I need to do to be tidy?

As always, thanks in advance!

  • 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-24T11:13:16+00:00Added an answer on May 24, 2026 at 11:13 am

    Well it depends. If you have a function defined or expressed below the divWindow for example, that would mean divWindow is considered reachable by the garbage collector, at least for as long as that function exists. In that case, setting divWindow to null would actually cause the GC to clean it up on its next cycle. However, if that’s not the case, “nulling” a variable won’t help it anymore than normal. If you posted the entirety of your code, I could probably tell you more.

    There is no explicit way to free up memory in javascript. The best you can do is to be aware of all references to your object, be aware of how reachable it is, and make sure the object is unreachable when you don’t need it anymore. After you do that, ultimately, you have to learn to trust the garbage collector, which isn’t so easy when you’re coding something that you want to run in IE for example.

    (ps: I also want to knock out a comment made above. The delete operator is for removing properties from an object. It doesn’t “delete” variables, and it doesn’t free up memory. In fact, javascript will throw if you do delete foo; in strict mode.)

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

Sidebar

Related Questions

I have a case that keeps coming up where I'm using a ListView or
I have a case where I need to translate (lookup) several values from the
I have a case where I wanna choose any database entry that have an
I have a JavaScript file that embeds a widget on a website. I want
I have a Javascript function that is passed a string. The string that it
I have a variable that can either be boolean false , or an integer
I have a variable called captcha from input in my form. In my javascript
I have a html component that includes some javascript. The component is a file
Have a form that is not being read by serialize() function. <script type=text/javascript> function
I have a jquery function ('rater') that I call this way: <div id=someID></div> <script

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.