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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:25:29+00:00 2026-05-25T06:25:29+00:00

var Obj = function(){}; var X = new Obj(); will X = null properly

  • 0

var Obj = function(){}; var X = new Obj();

will X = null properly clear memory?

Also would this be equivalent?

var Obj = function(){}; 
var X   = {}; 
X.obj   = new Obj();
delete(X.obj);

EDIT
It would seem that although deleting X.obj would NOT immediately clear memory, it would help the garbage collection. If I don’t delete X.obj, there would still be a pointer to an object and so the GC may not clean it up.

Although I’m picking @delnan’s answer, if you’re reading this you should def also catch Benubird’s article.

I also notice I accidentally wrote delete(X) originally instead of delete(X.obj) – sorry.

  • 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-25T06:25:29+00:00Added an answer on May 25, 2026 at 6:25 am

    The short answer is that you don’t. delete simply removes a reference (and not in the way you try to use it, see the above link – delete is one of those language features few people actually understand), nothing more. The implementation clears memory for you, but it’s not your business when (and even if, strictly speaking – this is why one shouldn’t rely on finalizers in GC’d languages that offer them) it does. Note though:

    • Only objects that can be proven to be unreachable (i.e. no way to access it) to all code can be removed. What keeps references to whom is usually fairly obvious, as least conceptually. You just need to watch out when dealing with lots of closures, as they may capture more variables than you think. Also note that circular references are cleaned up properly.
    • There’s a bug in old (but sadly still used) IE versions involving garbage collection of JS event handlers and DOM elements. Google (perhaps even SO) should have better material on my memory.

    On the plus side, that means you won’t get dangling pointer bugs or (save of course the aforementioned pitfalls) memory leaks.

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

Sidebar

Related Questions

Is it like... var obj = new Object(); obj.function1 = function(){ //code } or
For the following JavaScript: function EscapedString(str) { var obj = document.createElement(span); obj.innerHTML = str;
I have an on object like so var obj = {}; function set() {
What are the differences between these two codes in JavaScript? var obj = new
Objects in javascript throw me for a loop! In this set up... var obj
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
this is my demo code : <body onload=initialize()> <script> function initialize(){ var d='adddd' $.getScript('other.js',
<script type=text/javascript> var Person = { Create: function(name, age) { this.name = name; this.age
Is there an easier way to achieve the following? var obj = from row
How to get the value of key a and 'a' in javascript? var obj

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.