Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:28:38+00:00 2026-06-01T20:28:38+00:00

Horribleness aside, if I have a .NET webapp which has static variables scattered across

  • 0

Horribleness aside, if I have a .NET webapp which has static variables scattered across multiple classes, what is neatest way to ‘clear’ them all back to null.

Off the top of my head, it would be to restart the application using

System.Web.HttpRuntime.UnloadAppDomain() 

Reasons behind the question –
We are caching a few very large Dictionary collections which are expensive to create, and on the odd occasion need to be reset.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:28:39+00:00Added an answer on June 1, 2026 at 8:28 pm

    Unloading sounds the simplest way, but you wouldn’t want to do that very frequently; frankly I would be very dubious of any routine requirement to do this.

    If you wanted to do it without unloading, you’d have to look on a case-by-case basis to understand the implications. In particular, forcibly setting something to null that was set to a value by the static constructor / type initializer / static field initializer could thoroughly break your application.

    Note that static variables are rarely suitable for web apps, except perhaps for caches (and then must be carefully managed).

    If you genuinely do have data like this, rather than multiple static variables you might look at instance variables on a state class that is help as a pseudo-singleton – then you only have one reference to swap per cluster of data.

    Something that might be worth considering is having an event somewhere that the static code can subscribe to once only when initializing themselves, then trigger the event when needed, i.e.

    myStaticData = new SomeExpensiveThreadSafeCacheDictionary();
    GlobalKillSwitch.ResetCache += delegate { myStaticData.Clear(); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following horribleness: #include <iostream> struct thing { thing() { std::cout << thing
I'm trying to use ActiveRecord's find_or_create_by_*column* , but I'm getting errors from Postgres letting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.