Re: Q: global variable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Scott Allen (scott_at_nospam.odetocode.com)
Date: 02/14/05


Date: Mon, 14 Feb 2005 11:28:51 -0500

The life span of a variable is as long as the class instance it is
associated with, and the object will live for as long as you hold a
reference to the object. We typically don't hold a reference to a Page
object since they are only used to process a single request. You could
put an object reference inside the Session, Cache, or Application
objects to keep the object around a bit longer.

You can also mark a field as static (shared in VB.NET) and the field
will be around for the duration of the application. A static field
also means there is only one instance of the field in the entire
application - no matter how many objects get created - so you have to
be sure this is what your design really calls for. Globals like this
are a double edged sword.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 07:57:05 -0800, JIM.H.
<JIMH@discussions.microsoft.com> wrote:
>Hello,
>What is the life span of public variable defined in the class.
>Is there any way to define a global variable in aps.net, and use it in all 
>the following pages.
>Thanks,
>Jim.


Relevant Pages

  • Re: "Global" objects
    ... reference to a class instance. ... Static objects are problematic, and should be ... protected to a class instance that they reside in (other than the Form ... have a main form on which I show various user controls depending on ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: An object-oriented network DBMS from relational DBMS point of view
    ... The sentence has a context, it presumes a memory model, you can point ... "A class instance is explicitly created by a class instance creation ... In the context of the Java memory model, you need a reference to them ...
    (comp.databases.theory)
  • Re: How to Clone a class instance
    ... > Could anyone show me how to clone a class instance without writing code to ... contained objects), with some of them reference counted, blind memory ... instance1 is already a typed pointer (usually referred to as a "reference") ...
    (borland.public.delphi.language.objectpascal)
  • Re: Using USB flash as swap space.
    ... Do you have a reference of said article? ... Flash wears out from write operations and though it does ... use the studies have shown about an 8 month life span. ... "Life is like Linux - simple; if you are fighting it, ...
    (Ubuntu)
  • Re: is null allowed in C#?
    ... Fei Li wrote: ... obj is a variable, not a class instance. ... "This value isn't a reference to a class instance at all. ...
    (microsoft.public.dotnet.languages.csharp)