1.) Memory will be allocated when you create an instance of the class. When you call
Data1()
no additional memory is needed as you are only referencing fields of the class instance (and no other local variables). Since MyClass
is a reference type, memory will be allocated on the managed heap.
2.) Static methods do not consume any memory. Static fields are initialized before you access any static field or create any instance of the type they are contained in (
MyClass
in this case)
3.) You cannot create an instance of a static class so no memory is allocated dynamically, only when the type itself is created. Static classes are guaranteed to be loaded and to have their fields initialized and their static constructor called before the class is referenced for the first time in your program. Once created a static class remains in memory until your application domain is shut down.
No comments:
Post a Comment