473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How does static objects behave in ASP.NET

Hi,

I have a class with static fields. The values of those fields appear to
stick between Web requests. That behaviour is a bit of a surprise to me, as
I would expect the object to be completely destroyed between Web requests
(maybe not technically correct way of describing this, since the fields are
static, there is no object instantiation).

The static fields values do not seem to be shared between sessions though;
that's good.

Any additional info, or pointers to where I can read more about this on the
Net would be much welcomed.

Thanks.
Nov 19 '05 #1
4 1315
Uhm, why would a static field be destroyed? It is created when the
_type_ (not an object/instance of this type) is loaded and destroyed.

Also, they will be shared between session (they are similar to
application scoped variables), so I think you should retest that.

Nov 19 '05 #2
I have a few articles on the topic:
You'll find those statics fields are shared across sessions, in fact
each web application will have only one instance of each static field,
so you have to be very careful how you use them in a web app.

I have a few articles on the topic:

Get a Charge From Statics with Seven Essential Programming Tips
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Statics & Thread Safety: Part I
http://odetocode.com/Articles/313.aspx

Statics & Thread Safety: Part II
http://odetocode.com/Articles/314.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 3 Aug 2005 13:56:37 -0700, "Michael" <no****@nospam.com>
wrote:
Hi,

I have a class with static fields. The values of those fields appear to
stick between Web requests. That behaviour is a bit of a surprise to me, as
I would expect the object to be completely destroyed between Web requests
(maybe not technically correct way of describing this, since the fields are
static, there is no object instantiation).

The static fields values do not seem to be shared between sessions though;
that's good.

Any additional info, or pointers to where I can read more about this on the
Net would be much welcomed.

Thanks.


Nov 19 '05 #3
Thanks Stefan.
"Stefan" <Cl*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Uhm, why would a static field be destroyed? It is created when the
_type_ (not an object/instance of this type) is loaded and destroyed.

Also, they will be shared between session (they are similar to
application scoped variables), so I think you should retest that.

Nov 19 '05 #4
Thanks for the info and links.
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:f9********************************@4ax.com...
I have a few articles on the topic:
You'll find those statics fields are shared across sessions, in fact
each web application will have only one instance of each static field,
so you have to be very careful how you use them in a web app.

I have a few articles on the topic:

Get a Charge From Statics with Seven Essential Programming Tips
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Statics & Thread Safety: Part I
http://odetocode.com/Articles/313.aspx

Statics & Thread Safety: Part II
http://odetocode.com/Articles/314.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 3 Aug 2005 13:56:37 -0700, "Michael" <no****@nospam.com>
wrote:
Hi,

I have a class with static fields. The values of those fields appear to
stick between Web requests. That behaviour is a bit of a surprise to me,
as
I would expect the object to be completely destroyed between Web requests
(maybe not technically correct way of describing this, since the fields
are
static, there is no object instantiation).

The static fields values do not seem to be shared between sessions though;
that's good.

Any additional info, or pointers to where I can read more about this on
the
Net would be much welcomed.

Thanks.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Andy Leszczynski | last post by:
wikipedia (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) says: """ Python's support for object oriented programming paradigm is vast. It supports...
5
by: Noozer | last post by:
I have two Classes in use in an ASP application... The first Class is named "ORDER". It represents one job order. It has a Delete method, among others, which deletes it from my database. The...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
9
by: glue | last post by:
I have a class with a list member and the list seems to behave like it's static while other class members don't. The code... class A: name = "" data = def __init__(self, name): self.name =...
20
by: walterbyrd | last post by:
Reading "Think Like a Computer Scientist" I am not sure I understand the way it describes the way objects work with Python. 1) Can attributes can added just anywhere? I create an object called...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
13
by: cmrhema | last post by:
Hi, Kindly go through the code below public partial class _Default : System.Web.UI.Page { public static int i = 0; protected void Page_Load(object sender, EventArgs e) { }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.