Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If all of the labels come off of an object, programs can no longer access that object. That means C# can mark the object for garbage collection. That’s when C# gets rid of any unreferenced objects, and reclaims the memory those objects took up for your program’s use.
Here’s some code that creates an object.
For an object to stay in the heap, it has to be referenced. Some time after the last reference to the object disappears, so does the object.
Now let’s create a second object.
Let’s take the reference to the first object, and change it to point at the second object.