A friend called me today to ask me a question about a problem he’s experiencing with an asp.net application. The application is very slow and the CPU is very high. I asked him to check the amount of CPU time the application spends in the GC (MS recommends this to be at 30% at the peak times):
HINT If the .NET CLR Memory: % Time in GC performance counter indicates that your application is spending an average of more than 30% of its time in GC you should take a closer look at your allocation profile.
It was about 90% most of the time. After inspecting the code a bit he noticed that he calls the GC.Collect() on every hit to the server, the reason was that he has some classes that use com components and the com components are being released only when the GC runs. The solution was to use the IDispose pattern on those managed classes and manually releasing the com components instead of calling GC.Collect()