Something very strange

  • Thread starter Thread starter Annie
  • Start date Start date
A

Annie

Hi guys,

I have an object eg GlobalObject with some Public Static properties that I
set them throughout the session from each page.
I need these values to be shared among all the pages.

The funny part is that even I stop the application and close the IE etc
when i rerun the program still some of the
values not changed. Looks like that object is not removed by GC.

How can i remove this object to make sure all the values are gone when the
session is finished.

How can i make sure it is done?

TIa
 
Definition of the static keyword can be found here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfstaticpg.asp

It sounds as though you are writing a web based application, this means that when you stop using your application and close your browser this does not stop the application on the web server that processes the requests. This will only stop when the worker process on ther web server recycles or the web server is stopped.

Static variables live for the lifetime of the application so therefore what you are seeing is correct the variables will live unitl the worker process on the web server is terminated.

If you want to clear out a variable when a session finishes check out session_end '
protected void Session_End(Object sender, EventArgs e)' event in the glogal.asax.cs file of your project you can assign the variable to null in there.




HTH

Ollie Riches
 
Annie said:
Hi guys,

I have an object eg GlobalObject with some Public Static properties
that I set them throughout the session from each page.
I need these values to be shared among all the pages.

The funny part is that even I stop the application and close the IE
etc when i rerun the program still some of the
values not changed. Looks like that object is not removed by GC.

How can i remove this object to make sure all the values are gone
when the session is finished.

How can i make sure it is done?

TIa

In addition to what Ollie Riches said:

Watch out with static variables in a web environment, as they are
visible Application-wide. And the single web-application serves
all users, so that value is visible to *all* users!

Note: there is also a ...dotnet.framework.aspnet group, for ASP.Net
related questions.

Hans Kesting
 
Thanks guys for the reply.

I already did as Ollie was suggesting but I really didn't know why it was
happening.

Ollie,

How long the worker process remain active? even if I close the browser and
stop the application?

I think Hans suggestion is very appropriate I have to be careful for those
settings as it is a multiuser environemnt!

thanks
 
what version of IIS (web server) is the application running on? I guess you
are using an XP machine - it will have IIS 5.1

Ollie Riches
 
Back
Top