Such a statement as
is nonsense. First of all, all methods are static in nature, and non-static methods simply pass a hidden this parameter. So any method, whether static or not, takes up memory space. Second, optimizing memory should not be concerned with methods, but should focus on the life cycle of objects.
The
static modifier can be used with properties, methods, and inner classes to indicate static.
in a class, a static variable will have only one memory space, and although there are multiple class instances, the static variable in these class instances will share the same memory space. The variable of
static is initialized when the class is loaded. Static storage allocation is made at compile time.
static storage allocation means that the storage space requirements of each data target at run time can be determined at compile time, so that they can be allocated a fixed memory space at compile time.
therefore, the more static methods or properties you have, the fixed memory space will be allocated at the beginning, so most of the memory space will be allocated to static, and there will not be much memory space left, which will cause a memory burden.
as for memory leak pitfalls, it is another topic, not because there are too many static variables.
the static method itself will not cause memory leak, to access static variables or other things that cannot be released in the static method, which will lead to the hidden danger of memory leak
that person is simply talking nonsense.
is right. The static method itself will not cause the memory burden. If there is a problem, it must be caused by the wrong method. Instead of investigating "whether static will constitute a memory burden", Might as well optimize your own code