DoNotInitializeUnnecessarily

Name: Do not initialize unnecessarily
Level: Warning
Certainty: 90
File: Performance Rules
Category: Microsoft.Performance
Check Id: CA1805

Additional Information: Do not make initializations that have already been done by the runtime.

This rule asks that I comment out the line:

private System.ComponentModel.IContainer components = null;

In global.asax.cs for a web application. Doing this produces a compiler error,

'(Namespace).Global' does not contain a definition for 'components'

This rule appears to be incorrect in this instance.

[636 byte] By [AdamGetchell] at [2007-12-17]
# 1
Try changing it to private System.ComponentModel.IContainer components; because it is already null (done by the runtime ;))
PaulPaschedag at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2
As Paul notes, the issue here is the code that sets the declared reference to null. This is done by the runtime automatically, so the additional code in your destructor setting this variable (a second time) to null is unnecessary. This is an extremely local optimization that is unlikely to impact performance of a web app. For extremely performance sensitive code, unnecessary initializations have measurable impact (in fact, this rule was suggested to us by internal teams tuning very perf-sensitive API).

Other unnecessary initializations include setting primitive values (int, long, etc) to 0 or initializing a boolean to false. But again you should feel free to ignore or disable this rule if resolving this problem is unlikely to provide a measurable perf gain for your app.

MichaelFanning-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified