My job uses SonarQube as part of the CI/CD quality gate. One of the "Maintainability" issues (severity: medium) raised is the CA-1822: Mark members as static.
The link explains the added value of such change, but I am wondering: applying this change more than, say, 50 times - may not introduce memory issues due the fact that data necessary only for a specific point in time - will not be kept for the whole lifetime of the application?
Let's simplify, for the sake of the question: Suppose we have
class A
{
public int N1 {get; set;}
public string S1 {get; set;}
public A(int n)
{
N1 = NumHelper(n);
}
private int NumHelper(int n)
{
return Random.Shared.Next(0, 10) * n;
}
}
And say I get CA-1822 on member NumHelper.
Putting aside that this is absolutely negligible for the scenario above, if we will be applying such change tens or hundreds of times in the code base - the memory now required to keep these static members - once released after GC in the past - will never increase memory consumption in any significant manner?
In other words: non static class members (fields, methods) will not remain allocated forever. They will be GCed and the memory used for them released at some time. Changing (some of) them to static does not change this?