9.9. Garbage Collection

Every object you create uses various system resources, including the memory that holds the object itself. We need a disciplined way to give resources back to the system when they are no longer needed, so as to avoid “resource leaks.” The Common Language Runtime (CLR) performs automatic garbage collection to reclaim the memory occupied by objects that are no longer in use. When there are no more references to an object, the object is marked for garbage collection by the CLR. The memory for such an object can be reclaimed when the runtime executes its garbage collector, which is responsible for retrieving the memory of objects that are no longer used, so that the memory can be used for other objects. Therefore, whereas ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition 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.