Search Forum
(57415 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


              
Printable Version

C# Garbage Collector in Action
By Pavel Tskekov

Let's see how the garbage collector works.

I've made an application "Garbage Show" in which we have a class MyTextBoxClass, which derives from the TextBox class. In my newly created class I've put a static variable : instanceCount, which count current instances of the class.

A Timer components displays how many the current instances are. When I push the "Create New Instances" button I create a thousand instances, but because I set them all to a single variable , the count of the instances should be 1. BUT it stays 1000. This is because of the Garbage Collector.

Try clicking several times on the "Create New Instances" button to see the moment in which GC kills many of the instances.

Download GarbageShow.zip