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

  • Home
  • SEARCH
  • 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 621857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:55:17+00:00 2026-05-13T18:55:17+00:00

Just have a few questions in my mind… Is it a good practice to

  • 0

Just have a few questions in my mind…

  1. Is it a good practice to create an object without reference like the one below. If so, why?

    LoadIt(new myClass()); where LoadIt is some method

  2. What happens to the object created above. Will that be garbage collected. If so when? ie, is its scope same as other objects

  3. Is there any chance of referring the same object again?

  • 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-13T18:55:17+00:00Added an answer on May 13, 2026 at 6:55 pm

    The scope is decided by the Method (here LoadIt)…

    If the Load it methods stores its myClass parameter in a global variable, then until the global variable goes out of scope, the Object will stay in the memory… ie. It will not be garbage collected as the global variable is still referencing to it…

    Objects are generally stored in heap and can be referrenced by many variables that are in Stack… Here you dont want to hold the reference in the stack of your method… But it is referenced in the stack of LoadIt method by its parameter… Hence the object will not be garbage collected until the Load it method’s parameter goes out of scope… In the mean time the LoadIt method can try to reference it again in a global variable or pass it on as a parameter to another method… On a whole, only when all references for a object in stack (or in other objects) goes out of scope, the object is garbage collected…

    Getting back the reference to this object, purely depends on what the Load it method does with this object… If the method does nothing other than referencing it with the parameter variable, then you cant get it back… But if the method copies reference to other variable which is available public, then you can use that variable and get the reference back.

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

Sidebar

Related Questions

I just have a few questions about programmatically adding controls in aspx . After
I have just started programming and have made a few small applications in C
I have a few static pages that are just pure HTML, that we display
I have just started learning NHibernate. Over the past few months I have been
When i have a few content with work well. And if i just put
I've heard before that modules are just classes too. I have a few situations,
I have got a few tables which I am trying to join. I just
I have several database tables that just contain a single column and very few
I've been working with R just a few months, I have a problem with
I'm just starting with programming. I have a list of a few strings and

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.