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 706445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:10:02+00:00 2026-05-14T04:10:02+00:00

I am working on an existing project, setup by another coder. I’m having some

  • 0

I am working on an existing project, setup by another coder. I’m having some trouble understanding how state is being maintained between pages. There is a Class library which has some helper objects. Mostly these objects are just used for there static methods and rarely instantiated or inherited.

This is an example class I’m testing with.

public sealed class Application
{
    public static string Test;
}

Now when i run something like the following in the base class of my page, I would expect the result to be “1: 2:Test” all the time (note that “1” is empty), but strangly its only this way the first time it is run. Then every time afterwards its “1:Test 2:Test”. Somehow its maintaining the state of the static variable between pages and being refreshed??

Response.Write("1:" + SharedLibrary.Application.Test);

SharedLibrary.Application.Test = "Test";

Response.Write(" 2:" + SharedLibrary.Application.Test);

I need to create more classes like this, but want to understand why this is occurring in the first place.

Many Thanks

  • 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-05-14T04:10:02+00:00Added an answer on May 14, 2026 at 4:10 am

    As correctly stated by others: Anything declared as static variable in an Asp.Net application will keep its same value until changed.

    Here is what you really need to know:

    • This value will be lost when (not if, but when) the application pool recycles. Usually this happens daily, but also happens if you run out of memory or otherwise crash.

    • This value will be accessed by all the requests concurrently, i.e. multiple users, etc.

    So if this value is a counter for example:

    Response.Write("1:" + SharedLibrary.Application.Test);
    SharedLibrary.Application.Test = int.Parse(SharedLibrary.Application.Test) + 1;
    Response.Write(" 2:" + SharedLibrary.Application.Test);
    

    You might find unexpected output such as “1: 53 2: 55”. This would be a result of executing your test page at the same time from a couple of browsers.

    • Static variables always initialize when you first access or create an instance of the class. They all initialize. So if you have a large “bucket” o’ static variables (I call badly designed helper classes “buckets”), and you only use one of them, the memory for each one is still allocated at that time.

    • Finally, this value is never garbage collected. So if you put a large item in the static variable, then it will consume that memory as long as the process lives. (Please do not put Disposable resources, i.e. SqlConnection’s, in there.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer read is a Standard Additions command; ASTranslate doesn't support scripting… May 14, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer My question is how do we know which listeners we… May 14, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer I think it's just a matter that your selector is… May 14, 2026 at 7:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.