Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > When are static members garbage collected?

Reply
Thread Tools

When are static members garbage collected?

 
 
=?Utf-8?B?Sg==?=
Guest
Posts: n/a
 
      02-25-2004
I have an object that I am using in my ASP.net app. I only want one instance of this object available to all of my pages.

Here is a sample

public class statictes

private statictest() {} // static onl

private static string data = null

public static string Dat

ge

if(data != null) return data
data = "INIT"
return data

se

data = value




I am assuming that this private static member will no be garbage collected as long as the application is running. Is this correct? Would it be better to store it in cache (I should not expire until application end, and it does not have any dependencies)

Thank

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      02-25-2004
statics are GC'd when the appdomain is unloaded. (life of the application).

special note: your sample code is not thread safe.


-- bruce (sqlwork.com)




"J" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have an object that I am using in my ASP.net app. I only want one

instance of this object available to all of my pages.
>
> Here is a sample:
>
>
> public class statictest
> {
> private statictest() {} // static only
>
> private static string data = null;
>
> public static string Data
> {
> get
> {
> if(data != null) return data;
> data = "INIT";
> return data;
> }
> set
> {
> data = value;
> }
> }
> }
>
> I am assuming that this private static member will no be garbage collected

as long as the application is running. Is this correct? Would it be better
to store it in cache (I should not expire until application end, and it does
not have any dependencies)?
>
> Thanks
>



 
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
Thread safety problems with function scope static variables vs class static private members Hicham Mouline C++ 5 12-19-2008 08:10 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
About static const members appearing in another static const definitions Rakesh Sinha C++ 4 01-13-2005 08:11 AM
Instantiating a static class( Class with all static members - methods and variables) SaravanaKumar Java 6 10-19-2004 08:20 AM
Static classes with static members Ben ASP .Net 3 06-01-2004 07:43 PM



Advertisments