Tanzeel Tanzeel - 1 month ago 18
C# Question

How does CLR manage when a static method is called?

I have static class having static methods as shown below:

public static StaticTest
{
public static void DoSomeWork()
{
/// Do Some work
}
}


When
DoSomeWork()
function is called, how does CLR manage the function references as it is obvious that an instance of static class cannot be created?

What is the mechanism behind the scene to call the function in this case?

Answer

When the CLR loads an assembly containing static members, those members are placed in a dedicated space in memory called High Frequency Heap. Objects in the High-Frequency Heap are never Garbage collected to make sure that the static variables are available throughout the lifetime of the application.