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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:40:15+00:00 2026-05-13T19:40:15+00:00

I know that reference type will be garbage collected. I wanted to know whether

  • 0

I know that reference type will be garbage collected. I wanted to know whether value types will also be garbage collected from the stack?

  • 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-13T19:40:15+00:00Added an answer on May 13, 2026 at 7:40 pm

    It is very unclear what your question means. Can you carefully define what "garbage collected" means? Does it mean "are inputs to the GC algorithm", or "are deallocated by compacting the GC heap", or what?

    Values stored on the stack — whether values of value types or reference types — are the roots of the collection algorithm. They are not collected because they are the things that are alive that keep almost everything else alive.

    And obviously they are not deallocated by compacting the GC heap; they’re deallocated by popping the stack.

    Does that answer your question?

    UPDATE:

    What I mean by "garbage collected" is
    that, if a value type variable is
    found not to be used by the
    application then it will be removed
    from the stack

    OK, we’re getting closer to an answerable question here I think. Now we need to understand what exactly you mean by "removed from the stack".

    The stack is a block of pre-allocated memory one million bytes in size. Sometimes we use portions of that block of memory to store local variables of value type. What precisely do you mean by "removed from the stack"? The stack never changes in size; it’s a one-million-byte block of pre-allocated memory.

    The stack is divided into two contiguous regions, which we’ll call the "valid" and "invalid" sections of the stack. On x86 architectures the ESP register points to the boundary between those regions. Are you asking "under what conditions does the memory associated with a particular local variable of value type on the stack become a part of the invalid section based on a change in value of the ESP register on x86 architectures?"

    This might seem like a very, very "implementation detail" version of your question. The stack is an implementation detail of a specific version of the runtime, so if you’re going to ask questions about it, you’re going to have to accept the fact that you’re asking about a specific value in a specific register on a specific chip architecture.

    Further reading:

    References are not addresses

    The Stack Is An Implementation Detail, Part One

    The Stack Is An Implementation Detail, Part Two

    “Out Of Memory” Does Not Refer to Physical Memory

    I am a bit confused now to read what you have mentioned about "values" and "value types". I am finding it hard to understand the difference.

    It is tricky! We use the words "value" and "reference" to mean too many things. Let me sum up.

    A variable is a storage location.

    Every variable has a type. A type can be a value type or a reference type.

    A storage location contains a value.

    The value of a variable of value type is a value of the value type. For example, int is a value type. The value of a variable of type int is an int, say, 12.

    The value of a variable of reference type is a reference to an object of that type, or null. For example, string is a reference type. The value of a variable of type string is a reference to a string, or null.

    That’s why they’re called "value types" and "reference types". The value of a value type is an instance of the type. The value of a reference type is a reference to an instance of the type.

    Does that make sense now?

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

Sidebar

Related Questions

We know that string is a reference type , so we have string s=God
I know, that if i pass: primitive type, then copy of element will be
I know that capture-parenthesed subexpressions is counted in back reference numbering even when they're
I know that when it comes to passing objects in java, the reference of
Is it possible to assign by reference? I know that ref has to be
I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
I know that Java have its own garbage collection, but sometimes I want to
In C#, strings are reference type but behaves like value type. e.g. string str
I m trying to get the annotation details from super type reference variable using
I know that Phonegap has an event for back button, but it's only available

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.