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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:03:22+00:00 2026-05-17T02:03:22+00:00

I just read this question and the accepted answer: What is JavaScript garbage collection?

  • 0

I just read this question and the accepted answer: What is JavaScript garbage collection?

In the answer, Noldorin referenced some guidelines from Apple. Here is the part I’m concerned with:

Use delete statements. Whenever you create an object using a new statement, pair it with a delete statement. This ensures that all of the memory associated with the object, including its property name, is available for garbage collection.

I’m always taking time to keep up-to-speed on best practices, especially if I can reduce the memory footprint of my scripts. So I went off to test some things. If I understand correctly, the following is an example of an object that deletes itself after invoking a method.

var thing = function () {
    var a_method, and_another;
    a_method    = function() { /* do stuff */ };
    and_another = function() { /* do some other stuff*/ };
    this.init   = function() { a_method(); and_another(); };
};
delete new thing().init();

Usually I’ll wrap everything in a self invoking function and pass in my globals just like above. Everything is the same as I would normally do it, the only difference being that I added the delete right before the new.

The code works either way.

So the question is: Am I doing anything here? Is there some kind of benefit to deleting a reference to an object that only exists inside a function scope? Or am I just making things look confusing?

  • 1 1 Answer
  • 2 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-17T02:03:23+00:00Added an answer on May 17, 2026 at 2:03 am

    First of all the statement delete new scoped_object().init(); is not really doing anything, you should better take care about what variables remain in-closure or if you have circular references, which are the most common source of memory leaks.

    The delete operator is meant to be used to delete object properties, and it is really misunderstood, the answer you quote from @Noldorin quotes some text of the Apple JavaScript “Best Practices”, but they don’t have a clue about how delete works!!.

    They even recommend using delete on variable references, and that is not possible -only possible for variables declared in Eval Code-, because the var statement declares the variable as non-deletable ({DontDelete} in ECMAScript 3, or [[Configurable]] = false in ECMAScript 5) properties of the Variable Object -objects that form the scope chain-.

    Moreover, attempting to delete a reference to an identifier that is bound to an environment record – an identifier declared with a VariableDeclaration, FunctionDeclaration or from a function’s FormalParameterList-, causes a SyntaxError exception on the new ECMAScript 5th Edition under Strict Mode.

    I would recommend you to read the following article about delete:

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

Sidebar

Related Questions

I just read the accepted answer of this question , which left me with
I just read this great answer from BalusC about how to upload files with
I've just read this snippet from another answer : When you create a block
I just read this question: are there dictionaries in javascript like python? One of
I just read this question and stumbled upon the following quote: Scala treats ==
Note, this question is a bit subtle so read it carefully: I'm not just
I just read on this answer (answer has since been removed) and I'm sure
I just read this nice answer given on how to compare floating-point values for
I just read this question , and a solution states that: The fact that
I just read this question about packaging for Android: Android - Application (apk) Maximum

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.