In C# I understand that static variables are created in memory and live as long as the AppDomain lives. How do static methods get treated in memory? Do methods get created on the stack/heap like variables? Is there such a thing as method GC? How does this relate to the Call Stack, if it all?
Share
Methods live in the code segment, neither in the heap or the stack. The code is just loaded into memory, and stays there as long as the AppDomain lives.
Static methods and non-virtual methods just have an address, and the code uses the address directly when calling the method.
Virtual methods also have an address, but it’s not used directly. There is a pointer to the method in the virtual method table that is associated to the class, so the code gets the pointer from the table to find the method.
The call stack is just another term for the stack.