Summary

C# runs in an environment that includes an automatic garbage collector. Although this eliminates many of the problems associated with memory management in other languages, it introduces other concerns.

One of the primary issues is non-deterministic destruction. To resolve this problem, a good understanding of finalization is necessary to ensure resources are properly released.

The base class library includes a GC class designed to help work with the garbage collector. In most situations it's best to allow the garbage collector to run without intervention, but the GC class is there to help when necessary.

Weak references provide the ability to make objects available for garbage collection, yet give the program an opportunity to take the ...

Get C# Unleashed 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.