D
David
Consider the following singleton:
public sealed class Foo {
private static readonly Foo instance = new Foo();
private Foo() {
//Do init work
}
public static Foo Instance {
get {
return instance;
}
}
}
Once the Instance property is accessed like so:
Foo fooInstance = Foo.Instance;
and assuming fooInstance is not used anywhere else in the application,
the instance of Foo is *never* garbage collected and will last for the
lifetime of the AppDomain (which could be an ASP.net AppDomain) because the
private static field - instance - will always hold a reference to the
instance of Foo.
Is this correct?
Thanks.
public sealed class Foo {
private static readonly Foo instance = new Foo();
private Foo() {
//Do init work
}
public static Foo Instance {
get {
return instance;
}
}
}
Once the Instance property is accessed like so:
Foo fooInstance = Foo.Instance;
and assuming fooInstance is not used anywhere else in the application,
the instance of Foo is *never* garbage collected and will last for the
lifetime of the AppDomain (which could be an ASP.net AppDomain) because the
private static field - instance - will always hold a reference to the
instance of Foo.
Is this correct?
Thanks.