When I have a static field/property which lives in my application pool for the life of the application pool, where does it live in memory? I’m assuming its promoted into gen2 and lives out its days there? (assuming its small enough not to go into the LOH)
When I have a static field/property which lives in my application pool for the
Share
Static properties live in the heap in the memory space allocated to the type object for the type/class. They are loaded at the same time the type is loaded.
Static properties cannot be garbage collected. Type object can never be unloaded.
End of the chapter 4 of the book CLR via C# explains it. Here is a small snippet diagram:
This is just a portion of the diagram (cannot copy fully because of the copyright) and shows
Employeetype object with its static fields. Type object is similar to all other objects and has a pointer to its type which happens to beSystem.Type.