Does garbage collector reclaim value type memory
asp.net, c#, garbage-collection
Solution
When I declare int a = 0; as it is value type it gets memory from stack
That is correct -- assuming that the local variable is short lived -- but the logic is wrong. When you declare any short lived local it gets its memory from the short term memory pool, which might be the stack, or it might be a register. It gets its memory from the short term pool regardless of whether it is a value type or a reference to an object of reference type. Either way, the memory is allocated on the short term pool if the variable is short-lived.
That is, when you have a short-lived local
object x = null;
the storage for the reference to the object is allocated on the short term pool. The storage for the referred-to object, if there is one, is allocated on the long-term pool, the heap. In this case the reference is null.
when this variable goes out of scope does garbage collector reclaim this memory?
No. The garbage collector only collects memory that was allocated on the long term pool, also known as the heap.
The garbage collector of course must know about the short term pool; if there are references in the short term pool then those references might be to things that are alive. But the garbage collector can safely ignore all value types that do not contains references that are in the short-term pool.
Why are you asking the question? I suspect that there is a deeper question here that is being hidden.
Problem
When I declare `int a = 0;` as it is value type it gets memory from stack so when this variable goes out of scope does garbage collector reclaim this memory?