Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Question on Page lifecycle...

Reply
Thread Tools

Question on Page lifecycle...

 
 
=?Utf-8?B?RGlmZmlkZW50?=
Guest
Posts: n/a
 
      02-28-2006
Hello All,

I have a question which is pertinent to Page's lifecycle.

I declared a protected static object (global variable within that class)
whose value is set only once when the page is loaded. Will that object's
value be accessible
during consequent postbacks or is it set to null after HTML is rendered
initially?

I am assuming that it would be set to null because all the objects are
destroyed since Page object is killed after HTML has been rendered. In this
case ViewState does not make sense because it is an object and not a server
control.....correct?

Am I right or can anyone please explain me the concept?

Thanks a bunch!!!
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      02-28-2006
Hi,

if you have a static member, it will live as long as the AppDomain
(application) itself. So yes, it is accessible.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"Diffident" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello All,
>
> I have a question which is pertinent to Page's lifecycle.
>
> I declared a protected static object (global variable within that class)
> whose value is set only once when the page is loaded. Will that object's
> value be accessible
> during consequent postbacks or is it set to null after HTML is rendered
> initially?
>
> I am assuming that it would be set to null because all the objects are
> destroyed since Page object is killed after HTML has been rendered. In
> this
> case ViewState does not make sense because it is an object and not a
> server
> control.....correct?
>
> Am I right or can anyone please explain me the concept?
>
> Thanks a bunch!!!



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGlmZmlkZW50?=
Guest
Posts: n/a
 
      02-28-2006
Dear Teemu,

Thanks for your reply.

How about if I have a global variable not a static global variable. Would
its value be accessible for postbacks?

"Teemu Keiski" wrote:

> Hi,
>
> if you have a static member, it will live as long as the AppDomain
> (application) itself. So yes, it is accessible.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>
> "Diffident" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello All,
> >
> > I have a question which is pertinent to Page's lifecycle.
> >
> > I declared a protected static object (global variable within that class)
> > whose value is set only once when the page is loaded. Will that object's
> > value be accessible
> > during consequent postbacks or is it set to null after HTML is rendered
> > initially?
> >
> > I am assuming that it would be set to null because all the objects are
> > destroyed since Page object is killed after HTML has been rendered. In
> > this
> > case ViewState does not make sense because it is an object and not a
> > server
> > control.....correct?
> >
> > Am I right or can anyone please explain me the concept?
> >
> > Thanks a bunch!!!

>
>
>

 
Reply With Quote
 
=?Utf-8?B?RGlmZmlkZW50?=
Guest
Posts: n/a
 
      02-28-2006

Since every new request is served by a new thread how would .NET framework
persist this static values? Where I they stored in AppDomain? And where are
the normal variables and global variables stored in the AppDomain?

Thanks for clarifying me these concepts!!
"Teemu Keiski" wrote:

> Hi,
>
> if you have a static member, it will live as long as the AppDomain
> (application) itself. So yes, it is accessible.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>
> "Diffident" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello All,
> >
> > I have a question which is pertinent to Page's lifecycle.
> >
> > I declared a protected static object (global variable within that class)
> > whose value is set only once when the page is loaded. Will that object's
> > value be accessible
> > during consequent postbacks or is it set to null after HTML is rendered
> > initially?
> >
> > I am assuming that it would be set to null because all the objects are
> > destroyed since Page object is killed after HTML has been rendered. In
> > this
> > case ViewState does not make sense because it is an object and not a
> > server
> > control.....correct?
> >
> > Am I right or can anyone please explain me the concept?
> >
> > Thanks a bunch!!!

>
>
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      03-01-2006
> Since every new request is served by a new thread how would .NET
> framework
> persist this static values? Where I they stored in AppDomain? And where
> are
> the normal variables and global variables stored in the AppDomain?


Remember that a thread is not a class. Nor is it the programming heap. The
programming heap is created when the Application starts, and remains there
for the lifetime of the Application. All classes are stored in the heap when
they are loaded. A thread is simply a process that makes use of the
programming heap (and the programming stack). The difference is that an
instance class has multiple copies in the heap, while a static class has
only one.

Where things are stored depends upon what sorts of things they are. I'm
going to back up a bit and explain the heap and stack first. The heap is a
long-term memory storage area. The stack is a short-term memory storage
area. All reference types are stored in the heap. All primitives and value
types are stored in the stack. A reference type is a type that is not
accessed directly, but by means of pointers. A pointer is a special (value
type) variable that, in essence, stores the memory address of something
else. Pointers are placed on the stack, along with other primitives and
value types, like integers, structures, etc. The stack is sort of like a
scratch pad that a thread uses to keep track of things. The heap remains in
memory for the lifetime of the Application. So, when a thread creates an
instance of a class, a copy of that class is created in the heap, and a
pointer to that class is placed on the Stack. When you call a method in a
class, a copy of that method code is placed on the stack, and it executes.
If it changes anything in the class it belongs to, the change occurs in the
class instance in the heap. When you work with an instance of a class, you
are working with a pointer in the Stack, which points to that instance of
the class in the heap.

This is why Garbage Collection exists. You may have an instance of a class
in the heap which is no longer being used. That is, there are no other class
instances that reference it, and there are no pointers on the stack that
reference it. The class, however, is still there, in the heap. The Garbage
Collection in .Net patrols the heap, looking for such "orphaned" classes,
and cleans them up, eventually.

As for "global variables," that is a term that is not very descriptive of
anything. It could refer to any number of things, so I can't specifically
answer that question. "global" is a reference to "scope" which is somewhat
relative. For example, a variable can be scoped "globally" within a class.
In terms of an Application, there are any number of ways to store data
"globally."

But all of these things follow the same general rules I laid out for you
above. Here are a couple of articles that go into more detail about all of
this:

http://www.yoda.arachsys.com/csharp/memory.html
http://www.codeproject.com/managedcp...collection.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.




"Diffident" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Since every new request is served by a new thread how would .NET
> framework
> persist this static values? Where I they stored in AppDomain? And where
> are
> the normal variables and global variables stored in the AppDomain?
>
> Thanks for clarifying me these concepts!!
> "Teemu Keiski" wrote:
>
>> Hi,
>>
>> if you have a static member, it will live as long as the AppDomain
>> (application) itself. So yes, it is accessible.
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, AspInsider
>> Finland, EU
>> http://blogs.aspadvice.com/joteke
>>
>>
>> "Diffident" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hello All,
>> >
>> > I have a question which is pertinent to Page's lifecycle.
>> >
>> > I declared a protected static object (global variable within that
>> > class)
>> > whose value is set only once when the page is loaded. Will that
>> > object's
>> > value be accessible
>> > during consequent postbacks or is it set to null after HTML is rendered
>> > initially?
>> >
>> > I am assuming that it would be set to null because all the objects are
>> > destroyed since Page object is killed after HTML has been rendered. In
>> > this
>> > case ViewState does not make sense because it is an object and not a
>> > server
>> > control.....correct?
>> >
>> > Am I right or can anyone please explain me the concept?
>> >
>> > Thanks a bunch!!!

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to put page specific script in a page that inherits from a master page? Eric ASP .Net 0 04-24-2006 11:54 PM
Page not found error when navigating from the child page back to the parent page Samy Java 0 02-04-2006 01:29 AM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy ASP .Net 2 08-15-2005 03:30 PM
RE: Web page is not available - "The Web page you requested is not available offline. To view this page, click Connect" =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?= ASP .Net 0 06-07-2004 07:11 AM
Re: Web page is not available - "The Web page you requested is not available offline. To view this page, click Connect" Natty Gur ASP .Net 0 06-06-2004 05:46 AM



Advertisments