Suppose I have a C# static class. It contains only only static methods. How do I calcute the size of it? What does affect its size in the memory?
And how much would it weigh if I included static fields?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll never be creating any instances of it, so the size is pretty much irrelevant.
Obviously as you add more methods they will take some memory (the IL, the JIT-compiled native code etc) but no more so than anywhere else – and almost certainly not significantly within your app.
If you add some static fields, again those take up memory – but they’re only associated with the type, rather than any instances of the type. So if you add (say) a static field of type
long, that will take an extra 8 bytes perAppDomainyou load the type into. Insignificant in the grand scheme of things.