Microsoft .NET: Jumpstart for Systems Administrators and Developers

3.10 Memory Management and the CLR

3.10 Memory Management and the CLR

Automatic memory management is a service that you get with the CLR during managed execution. The CLR garbage collector will oversee the allocation and deallocation of memory, saving the developer having to write acres of memory management code, possibly getting it wrong, and crashing the application.

When a new process is started, the CLR puts aside a chunk of memory, which is called the managed heap. The managed heap contains a pointer, initially set at the base address, to the address where the next object in the heap will be allocated. All reference types are allocated on the managed heap, and the CLR will automatically allocate address space from the heap as long as there are enough addresses in the address space.

This process is extremely fast since the CLR manages objects consecutively in a contiguous block in the heap.

Garbage collection works by deciding the best time to take back some memory. By working in a series of generations, the garbage collector determines how recently an object has been used. When the first generation (actually generation 0) is full it will then perform what is known as a collection and release memory held by objects that are no longer being used.

Memory-collection decisions are based on an application s roots, which either contain a null or a reference to an object. An internal graph is created of objects that can be reached from these roots: any object that does not figure on this graph...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Waste Compactors
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.