We have been going through a big memory leak analysis and have found one of the contributing factors has been the non removal of delegates on events causing objects to not be GCed quickly enough (or sometimes forever).
Would anyone have any ideas as to how to write a rule in FXCop to ensure that we have delegates are removed from handlers?
I’ve just seen this and as such I’ll ask there for more information.
Ok, beside the problem of implementing the actual check (in my opinion this is very similar to a path coverage and thus not practical) – here is the way to write a new FxCop rule it:
At first some articles that helped me once:
Writing Your Own Custom Rules
Three Vital FXCop Rules
Implementing a simple rule is no big deal. In your project you need a Rules.xml file as an embedded resource (see here). You derive your class from
BaseIntrospectionRuleand add your code to the Check()-method:I did this some times ago. I hope it still works as described 🙂