O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Garbage Collection: Automatic Dynamic Memory Management

Whereas classes are written in the source code before a program is executed, their object counterparts are created dynamically during runtime by using the new operator as described earlier. Every instantiated object occupies a certain amount of memory needed to store items, such as the object's instance variables. Because memory is a scarce resource, it is important to reclaim and thereby recycle the memory representing objects that are no longer used in the program to make space for newly instantiated objects coming into use.

How Do Objects Get Out of Reach?

Before we look at how C# performs this reclaim, it is worth looking closer at what we mean by “an object no longer used.” Briefly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required