Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   When are static members garbage collected? (http://www.velocityreviews.com/forums/t73993-when-are-static-members-garbage-collected.html)

=?Utf-8?B?Sg==?= 02-25-2004 11:41 PM

When are static members garbage collected?
 
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


bruce barker 02-25-2004 11:58 PM

Re: When are static members garbage collected?
 
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" <anonymous@discussions.microsoft.com> wrote in message
news:B028C369-111F-4661-AFB4-5B31DF1DA3F7@microsoft.com...
> 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
>





All times are GMT. The time now is 01:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.