static field lifespan

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I understand that static variables have app-domain scope. Till the app-domain
is in memory, the static variable will be in memory. When are the app-domains
unloaded is the question. I have read somewhere in this forum that statics
live till the asp.net process is recycled. Please clarify if someone can.
Thanx!
 
The ASP.Net worker process can be recycled under a number of scenarios. You
can control these normal scenarios by going to:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG

(c:\winnt on 2000 and framework version might be different) and opening
machine.config (don't mess around in there!). Find "processModel
Attributes" and you'll find documentation describing a number of settings -
some of which are used for controlling when the worker process is recycled.
In IIS 6.0, there's an ASP.net tab which controls much of these things
(maybe even all,dont' remember).

basically the worker process can recycle itself at certain times/intervals,
when the memory reaches a certain amount, after being idle for too long and
so on. The worker process also terminates when IIS is restarted, or the
web.config file touched

Of course, the worker process can abnormally termniate...like if the system
crashed ;) or some cltr-alt-deletes the process...

Karl
 
Karl,
I undertand that. My question was more to do with the lifespan of a "static"
variable. When does the statc variable really becomes unreachable?
 
the lifespan of static variables is directly tied to the lifespan of worker
process. Static variables are tied to the appDomain...whenever a worker
process recycles, it stops its parent appdomain and starts a new one - state
is not transfered from one to another. This should be useful:
http://odetocode.com/Articles/305.aspx

I'm not sure if this was mentioned in the initial thread, but the real risk
with static variables is that you risk having serious race conditions..check
out: http://odetocode.com/Articles/313.aspx

Karl
 
Thank you!

Karl Seguin said:
the lifespan of static variables is directly tied to the lifespan of worker
process. Static variables are tied to the appDomain...whenever a worker
process recycles, it stops its parent appdomain and starts a new one - state
is not transfered from one to another. This should be useful:
http://odetocode.com/Articles/305.aspx

I'm not sure if this was mentioned in the initial thread, but the real risk
with static variables is that you risk having serious race conditions..check
out: http://odetocode.com/Articles/313.aspx

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top