Interacting with the Garbage Collector

The System.GC class provides several methods for manually interacting with the garbage collector. In this chapter you already learned some of them. Remember Collect that enables forcing a garbage collection; WaitForPendingFinalizers enabling to wait for all Finalize methods to be completed before cleaning up resources; ReRegisterForFinalize that puts an object back to the finalization queue in object resurrection; and SuppressFinalize that is used in the Dispose pattern for avoiding unnecessary finalizations. There are other interesting members; for example, you can get an approximate amount of allocated memory as follows:

Dim bytes As Long = System.GC.GetTotalMemory(False)

You pass False if you do not want ...

Get Visual Basic® 2010 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.