Garbage Collection

for RuBoard

Garbage collection is not a new idea by any means. It has been used in languages such as LISP and Perl for many years . However, many popular programming languages have not incorporated it. For example, C/C++ programmers have had to deal with allocating and freeing memory for decades. In addition, COM programmers have had to keep accurate ref counts to make sure COM objects were deleted at the right time. While programmer management of memory allows for quite a bit of freedom, it also has been the source of an untold number of memory leaks and premature deallocations.

Basically, in an environment that supports garbage collection, a programmer still has to say when memory should be allocated. In the .NET Framework, this occurs whenever a new object is created. However, once the programmer has finished using the object, she doesn't have to remember to explicitly free or delete it. Instead, the garbage collector will periodically sweep through all allocated objects to see which ones are no longer being used. Those objects can be freed to reclaim the memory.

Garbage collection is not a panacea for resource allocation. There are many unmanaged (non-memory) resources that a programmer will still have to manage. For instance, if an object is holding an open file handle, that handle should be explicitly closed by the programmer when the object is no longer needed.

NOTE

Sometimes, unmanaged resources used in .NET Framework classes are scarce and need to be freed as soon as possible. For these unmanaged resources, the .NET Framework created the IDisposable interface. Classes that need to quickly free unmanaged resources should implement this interface, which contains one method, Dispose . See the .NET Framework SDK for more information on how to use Dispose .


for RuBoard


. NET Framework Security
.NET Framework Security
ISBN: 067232184X
EAN: 2147483647
Year: 2000
Pages: 235

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