Garbage Collection and Object Lifetimes

The programming model of the CLR is based on the premise that the system is responsible for allocating and managing the memory for types, values, and objects. As a consequence, programmers using the .NET Framework do not have to worry about allocating and managing memory. In fact, when you are writing managed code that will run under normal conditions (i.e., safe mode), it is illegal to directly allocate memory or to directly access memory through the use of pointers.

The CLR's memory management scheme presents challenges for programmers who are making the transition from unmanaged languages such as C and C++. These programmers have been conditioned to use a very hands-on style of memory management in their ...

Get Building Applications and Components with Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.