In my experience, the .net GC is a piece of **** and shouldn't be trusted.
We have found a number of production bugs that have been solved by a
single introduction of GC.Collect.
You need to read up on Garbage Collection. The .Net platform uses the best
Grabage Collection of any object-oriented software development platform,
better than Java, better than anything else.
Individual personal experiences don't make for reliable data. Statistics do.
Chances are, you're playing fast and loose with your memory management.
Garbage Collection is not a substitute for good memory management. I have
heard many stories of, for example, apps that ate up all the system memory
by reassigning strings without restraint. A string is an immutable array of
char. When you reassign it (by any number of methods, including
concatenation), you create a new array the size of the new string, and the
old string is discarded. Concatentaion is almost worse than reassignment. It
throws both source strings away and replaces them with a single array that
is the sixe of both the original strings combined. This is why the
StringBuilder class was developed.
There are many ways to be irresponsible with memory.
try it - make any batch routine that say - traverses your disk, opens each
file and computes a checksum, and run it with task manager open - it's
quite an eye-opener. The memory just goes up... and up... and up...
This sounds like one of them. Do you realize how many files are on a
typical Operating System these days? Do you know how expensive it is to use
IO, much less open a file? that is why the CLR includes classes like the
FileInfo and DirectoryInfo classes.
Like anything else, as good as it is, the .Net Platform can be (and often
is) abused by those who are either too lazy or too ignorant to use it
correctly. Nothing in this world can withstand literally anything you throw
at it. Why, it is even possible to destroy a monumental structure like the
World Trade Center, if you just fly a fully-loaded commercial airliner into
it.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.