Remove calls to GC.Collect()
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>
Open in the interactive Rules Explorer · All default rules
.NET Framework Usage / System: all 12 items
- Mark ISerializable types with SerializableAttribute ND2200
- Mark assemblies with CLSCompliant (deprecated) ND2201
- Mark assemblies with ComVisible (deprecated) ND2202
- Mark attributes with AttributeUsageAttribute ND2203
- Remove calls to GC.Collect() ND2204
- Don't call GC.Collect() without calling GC.WaitForPendingFinalizers() ND2205
- Enum Storage should be Int32 ND2206
- Do not raise too general exception types ND2207
- Do not raise reserved exception types ND2208
- Uri fields or properties should be of type System.Uri ND2209
- Types should not derive from System.ApplicationException ND2210
- Don't Implement ICloneable ND2211