In .NET, do the number of methods or the size of the methods (i.e., amount of code) within an object affect the amount of memory the object uses when it is instantiated?
EXAMPLE: Will an object with 3 int properties and 1 method take up more memory than an object with 3 int properties and 20 methods?
If "yes", do static methods take up less memory?
Please note: I realise that actually calling a method might instantiate other objects or variables that will use memory - my question simply relates to how much memory they use after calling the constructor.
No. Methods take up memory but that's very little. The method table as well as the code generated for the method is shared by every instance of the object.
Will an object with 3 int properties and 1 method take up more memory than an object with 3 int properties and 20 methods?
The answer is no. Methods aren't part of any particular instance. They belong to the type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With