1

I need to change a static property on an object in our web application. The property has a default value that is hard-coded into the object. If I change the static property in my Application_Start does that change stick:

A) Forever (well, until the app is recycled)

B) Until the object is GC'd then re-inialised by the next accessor

C) Depends

Note that the property I'd be setting is just a String

3 Answers 3

3

The scope of a static variable is its AppDomain. So no, it won't get garbage collected - but if the AppDomain is recycled (which can happen a fair amount in ASP.NET) then you'll end up with a "new" static variable, effectively.

1

In my experience with our web apps here, the answer is A. As far as I know, a static class will never be GCed, it lives on for the life of the process (in this case, the ASP.NET worker process)

1
  • 1
    Life of the AppDomain, not process.
    – Jon Skeet
    Commented Oct 28, 2008 at 11:11
1

Go for A) App Instance Variable

For context storage, refer to httpContext.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.