Remove calls to GC.Collect()

Rule ND2204 .NET Framework Usage / System

Calling GC.Collect() directly can lead to performance issues. More: http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx Matches methods calling any GC.Collect() overload.

How to fix

Remove matched calls to GC.Collect().

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Remove calls to GC.Collect()</Name>
// <Id>ND2204:RemoveCallsToGCCollect</Id>

warnif count > 0 

let gcCollectMethods = ThirdParty.Methods.WithFullNameWildcardMatch(
   "System.GC.Collect(*)").ToHashSetEx()

from m in Application.Methods.UsingAny(gcCollectMethods)
select new { 
   m, 
   gcCollectMethodCalled = m.MethodsCalled.Intersect(gcCollectMethods),
   Debt = 5.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* shouldn't call *GC.Collect()* 
// because doing so can lead to performance issues.
//</Expl>

//<Desc>
// Calling **GC.Collect()** directly can lead to performance issues. More:
// http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx
// Matches methods calling any *GC.Collect()* overload.
//</Desc>

//<HowToFix>
// Remove matched calls to *GC.Collect()*.
//</HowToFix>

.NET Framework Usage / System: all 12 items