I'd say it depends on the time you call :
Application["pvtDataDictionaryDs "]= pvtDataDictionaryDs ;
If you call it in the Global.asax constructor, then each time an Global.asax
object is created, it is replaced (and if you have multiple users at the same
time, it can be often). If you call it in Application_Start, it will be
created only when the first HttpApplication is created, thus only once per
application domain creation. I don't think it's a good idea for the
pvtDataDictionaryDs object to be an instance member of the Global.asax class
; it should not be garbage collected when the Global.asax object is, since it
is referenced in your HttpApplicationState object, but who knows, maybe the
link between your object and the HttpApplicationState object is a weak
reference, not valid for the garbage collector.
Try the following :
protected void Application_Start(Object sender, EventArgs e) {
DataSet pvtDataDictionaryDs = new DataSet();
// Load it
Application.Lock();
Application["pvtDataDictionaryDs"]= pvtDataDictionaryDs ;
Application.Unlock();
}
and see what happens... If the object expires, it means that all objects put
into HttpApplicationState that are not referenced outside it end up garbage
collected ! I would call that a bug...
Vishwanathan Raman said:
Francois:
Thanks for the insight.I create both the objects in Global.asax file.
eg
public static DataSet DataDictionaryDs = new DataSet();
private DataSet pvtDataDictionaryDs = new DataSet();
Application["pvtDataDictionaryDs "]= pvtDataDictionaryDs ;
pvtDataDictionaryDs =null;
I find that the one in Application State expires and the static remains
active.
François Lemaire said:
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).
If I read the documentation for HttpApplicationState, it says that one and
only one HttpApplicationState object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplicationState are static singletons that reside
inside the application domain of your ASPNET application.
I think that if it looks like HttpApplicationState expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.
Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplicationState ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.
Hope this Helps
François