473,320 Members | 1,909 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,320 software developers and data experts.

How to store objects in application state?

Mel
This may be a stupid question, but here goes...

I have created a NameValueCollection in my website's application state. If,
during a page request, I add a string key and string value to the
collection, how are they stored? Strings are objects so I'm really only
passing references, right? Now I assume that request handlers run in
different threads with their own memory spaces, and when the request ends,
the memory space is unaloted, taking with it my string objects. What am I
missing here?
Nov 18 '05 #1
2 1995

Hi Mel,

A point you are missing can be the fact that the application state bag is
not deallocated when the request ends. The application state bag (referenced
by this.Application) is active as long as the application runs and it's an
application wide storage area.

When you pass a string to the application object, the reference of the
string object is passed so you are right on that. When the application
shutdowns, then this reference is gone and at this moment, the string is now
garbage. Since string is a managed type, it's garbage collected
automatically. Coming back to the namevalue collection, your application
state bag keeps a reference to the namevalue collection on the memory. All
other objects kept inside the namevalue collection are referenced through
this reference. Namevalue collection simply keeps reference to objects that
you store in it. So once this reference to the namevalue is gone, so are the
references to other objects.

In general, there are levels of storage options in ASP.NET. You can store
variables on the page level, on the session level and on the application
level. All of them work similiarly as described above, with the exception of
when they are destroyed.

When you create the string on the page, you get a reference and this
reference is destroyed when the page object is deallocated. But, since you
add the string also to the namevalue collection, which is active in the
Application state bag, another reference is still pointing at it. So it's not
lost, hence it's not deallocated.

Ethem Azun

"Mel" wrote:
This may be a stupid question, but here goes...

I have created a NameValueCollection in my website's application state. If,
during a page request, I add a string key and string value to the
collection, how are they stored? Strings are objects so I'm really only
passing references, right? Now I assume that request handlers run in
different threads with their own memory spaces, and when the request ends,
the memory space is unaloted, taking with it my string objects. What am I
missing here?

Nov 18 '05 #2
Mel
Thanks Ethem,

so basically object lifetime issues are the same across threads as they are
within a thread. The main thing I have to deal with is concurrent access to
shared objects. To do this I use such things as C#'s lock() mechanism, and
the synchronised wrappers available for some intrinsic classes such as
Hashtables.

"Ethem Azun" <Et*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...

Hi Mel,

A point you are missing can be the fact that the application state bag is
not deallocated when the request ends. The application state bag
(referenced
by this.Application) is active as long as the application runs and it's an
application wide storage area.

When you pass a string to the application object, the reference of the
string object is passed so you are right on that. When the application
shutdowns, then this reference is gone and at this moment, the string is
now
garbage. Since string is a managed type, it's garbage collected
automatically. Coming back to the namevalue collection, your application
state bag keeps a reference to the namevalue collection on the memory. All
other objects kept inside the namevalue collection are referenced through
this reference. Namevalue collection simply keeps reference to objects
that
you store in it. So once this reference to the namevalue is gone, so are
the
references to other objects.

In general, there are levels of storage options in ASP.NET. You can store
variables on the page level, on the session level and on the application
level. All of them work similiarly as described above, with the exception
of
when they are destroyed.

When you create the string on the page, you get a reference and this
reference is destroyed when the page object is deallocated. But, since you
add the string also to the namevalue collection, which is active in the
Application state bag, another reference is still pointing at it. So it's
not
lost, hence it's not deallocated.

Ethem Azun

"Mel" wrote:
This may be a stupid question, but here goes...

I have created a NameValueCollection in my website's application state.
If,
during a page request, I add a string key and string value to the
collection, how are they stored? Strings are objects so I'm really only
passing references, right? Now I assume that request handlers run in
different threads with their own memory spaces, and when the request
ends,
the memory space is unaloted, taking with it my string objects. What am I
missing here?

Nov 18 '05 #3

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

Similar topics

9
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using...
3
by: Samuel R. Neff | last post by:
Is there any downside to using the Memento pattern to store the current state of an object instead of using private fields for internal state and a memento just for some bookmarked state? Seems...
5
by: Joakim Westman \(Elicit AB\) | last post by:
Hi! I have a page that generates a lot of HTML, and I am considering different solutions to constrain the amount of code that is sent back to the client. One thing I thought about is the...
2
by: Chris | last post by:
Hi, I am building a single webform/webpage asp.net application using VB.NET. I have created lots of classes for this web application. On page load I use a facade controller pattern class to...
3
by: ExclusiveResorts | last post by:
Can the CallContext be used reliably for storing request specific data? We are developing an application library that uses the CallContext to keep an IdentityMap (hashtable of business objects...
1
by: GS | last post by:
I have system wide connection string defined in web.config. Is it possible to store connection object in global variable accessible by whole application and get reference to it in different parts of...
0
by: Leonid Levin | last post by:
Hi, I am builidng an ASP.Net web application consuming a .Net web service. The web service requires me to log in and keeps my login status in its own session state. I don't want to log in every...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
2
by: Alan Silver | last post by:
Hello, I am designing a form that allows people to request the formation of a limited company. When they fill in the form, they have to supply a certain amount of information relevant to their...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.