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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:17+00:00 2026-05-28T04:08:17+00:00

Within instances of objects I like to use the closure mechanism to simulate private

  • 0

Within instances of objects I like to use the closure mechanism to simulate private member variables. For a potential large number of created objects I don’t need some of the private members though, but I have to declare them for them to be used in the closure, like “one”, “two” and “three” here:

    var obj=function()
    {
        var one;
        var two;
        var three;

        var M=function()
        {
            one=5;
        };
    };

(Don’t mind that this is not actually a working example of my setup, it’s just to demonstrate the use of the closure over the three vars with M.)

Do the var statements themselves already consume memory, or does that depend on actually assigning something to these vars like with “one”?

  • 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-28T04:08:18+00:00Added an answer on May 28, 2026 at 4:08 am

    The interpreter has to store information about scope – one = 5 will change the local variable one instead of creating a global variable (which would happen with e.g. four = 5). This information must cost some memory somehow. This memory usage also applies before assigning a value to one, because the information has to be available at the time you’re assigning.

    How much memory it will cost is difficult to say since it differs per interpreter. I guess it isn’t enough to worry about.

    Note that two/three are not used at all and may be garbage collected in this example. (Actually, you don’t expose M either, so everything may be garbage collected right away in this example.)

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

Sidebar

Related Questions

i am trying to change the count attribute within instances, the xml is below
I am trying to deploy my JPA application on 2 separate instances within the
I need to find all instances of strings within an xml node. To be
Within a Javascript object ( testObject ) I am populating an array with objects
I'm learning C# and created a class within my program that holds a random
When I use static variables in C++, I often end up wanting to initialize
I have objects that use the keys updated_at and created_at which have string timestamps
I am making a top-down shooter that makes extensive use of TMX maps created
I have a Task class wich has a string text private member. I access
According to MSDN (Section 11.3.6 of the C# spec ): Within an instance constructor

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.