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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:20:48+00:00 2026-05-17T22:20:48+00:00

Anyhow, If I were to write something like: var h = 5; delete h;

  • 0

Anyhow, If I were to write something like:

var h = 5;  
delete h; 

…I’d be eliminating the reference, but not the memory.
Now, if I set the variable to null, would that replace the memory with the null object?

var h = 5;  
h = null;

If so, wouldn’t it be better to not only delete() the reference, but also replace the memory with a null object, for better memory optimization?

var h = 5;  
h = null;  
delete h; 

If I want to create a bucket-load of dynamic objects in a long and complex script, what’s the best way to get rid of, or otherwise induce the garbage collector to eliminate, objects? Because in addition to just eliminating references, I had read that you could hint the collector to free memory if it was occupied by null…

  • 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-17T22:20:48+00:00Added an answer on May 17, 2026 at 10:20 pm

    There’s no destroy. You’re probably thinking about delete, but delete can’t be used to delete variables, only properties. (Although currently browsers let you get away with it, with varying results.) You can delete global variables by removing them from window, but not locals.

    Anyway you don’t need to think about this sort of stuff in JavaScript. Set a variable to null and if there are no more variables pointing to the same object, it’ll get garbage-collected at some point in the near future. The amount of space taken up by the record of the variable pointing to null is tiny and not worth worrying about. Unless you are making a deliberate closure it’ll fall out of scope anyway when the local function exits, becoming eligable for GC.

    I had read that you could hint the collector to free memory if it was occupied by null…

    Nope. You’re just removing the references, the GC will pick up the now orphaned objects and free the memory at its own leisure. You don’t get any say in the matter.

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

Sidebar

Related Questions

Here goes newbie question number 5, but I don't have a teacher.. so.. anyhow
I am trying to set up a tagging system, but i am having a
Hey guys, with a lot of help from you i was managed to write
PHP allows Unicode identifiers for variables, functions, classes and constants anyhow. It was certainly
I am trying to learn pyparsing. It sounds promising and something that would be
I am creating my simple implementation of the String class like in the .Net
I don't understand how to make a job use the same output directory directory
I am trying to retrieve data from MySQL for a flash application via PHP,
I've read about scrypt and some of its advantages over the bcrypt hashing algorithm
I am writing a simple personal app that has a browser control and I

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.