Are static class instances unique to a request or a server in ASP.NET?

Technology CommunityCategory: ASP.NETAre static class instances unique to a request or a server in ASP.NET?
VietMX Staff asked 3 years ago
Problem

On an ASP.NET website, are static classes unique to each web request, or are they instantiated whenever needed and GCed whenever the GC decides to disposed of them?

Your static classes and static instance fields areĀ shared between all requests to the application, and has the same lifetime as the application domain.

Therefore, you should be careful when using static instances, since you might have synchronization issues and the like. Also bear in mind, that static instances will not be GC’ed before the application pool is recycled, and therefore everything that is referenced by the static instance, will not be GC’ed. This can lead to memory usage problems.