I started reading of c# 5.0 in a Nutshell
and now I am on Stack and Heap chapter
There is example of how GC works with heap objects:
StringBuilder ref1 = new StringBuilder ("object1");
Console.WriteLine (ref1);
// The StringBuilder referenced by ref1 is now eligible for GC.
So author saying that ref1 object is ready for GC after Console.WriteLine, but what if I want to use ref1 object later in my program?
As long as you’re using the reference to an object it will not be eligible for collection. The point of the example is to show that since
ref1is no longer accessed by the code, the object could be collected at any point after this.