An Introduction to .NET Memory Management

I l @ ve RuBoard

A .NET fact that has a lot of people interested, worried, or just plain dumbstruck is that .NET runtime memory management is a garbage-collected (GC) system. Old programmers in particular have nightmares about the days of Lisp, when waiting for the garbage collector was a painful experience because he only came on Tuesdays. C++ programmers have had memory management drummed in to them so hard that to relinquish control of those allocations and deletions is anathema to them.

The .NET memory management system approaches the allocation of memory resources differently. A block of memory allocated in the garbage collected or managed heap maintains a record of all the objects that refer to it. Only when those references have been released is the object destroyed . This relieves the burden of memory management from the programmer. You no longer have to remember to delete memory; you just stop using it. A class no longer has to keep track of reference counts. It knows when to delete itself. To reduce heap fragmentation, the GC also moves objects to consolidate the used and free spaces in the managed memory store.

This prevents memory leaks and improves performance of heavily stressed server systems. The managed heap also ensures that unsafe accesses , like buffer overflows and crashes, cannot modify the data associated with other programs running on the same system. This makes the whole operating system more reliable and secure. Garbage collected systems have an unfair reputation for being slow and inefficient, but Microsoft has gone to considerable lengths to ensure that garbage collection in .NET really works. It's very fast and does not impose a significant load on the CPU. Generally, on a Windows 2000 “based machine, the GC will require only around 1/1000 of the total processor time.

Finally, for programmers who require the use of pointers to blocks of memory, there is provision in the system for what is called "unmanaged" or unsafe memory and code. This is so that you can use your old structures or legacy C++ “based applications side-by-side with.NET features.

I l @ ve RuBoard


C# and the .NET Framework. The C++ Perspective
C# and the .NET Framework
ISBN: 067232153X
EAN: 2147483647
Year: 2001
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net