5

I am working on a project that implements the IDisposable interface. During this project, I found out my knowledge of the GarbageCollector can be best described as poorly. So I started reading some documentation and finally I found the "Fundamentals of Garbage Collection" article on MSDN.

You have to understand that at this point I always thought the GarbageCollector was the man working in the sewers who cleaned up the waste coming from the Program. Therefore I was surprised to read the following snippet:

After the garbage collector is initialized by the CLR, it allocates a segment of memory to store and manage objects.

A paragraph later, the document states:

To reserve memory, the garbage collector calls the Win32 VirtualAlloc function, and reserves one segment of memory at a time for managed applications. The garbage collector also reserves segments as needed, and releases segments back to the operating system (after clearing them of any objects) by calling the Win32 VirtualFree function.

If I understand correctly, the GarbageCollector is actually the MemoryManager of a .NET program!

I know, it still collects garbage. But isn't that like calling a singer a microphone holder? Sure, it's true, but hardly the reason you'd pay money to see them. The GarbageCollector does apparantly so much more than waste disposal, it hardly seems fair to call it just a GarbageCollector.

So in conclusion:

Did I understand correctly? Or am I way off?

And if I did understand correctly: why did the .NET developers call it a GarbageCollector?

4

4 に答える 4