Singleton/static member question...
-
Can someone explain to me the lifetime of a static member variable? That is, in a singleton, one has a static member variable of the single instance and a static member function which returns a reference to that instance. How is it that, 1) the static member variable is maintained, 2) the static member variable is destroyed (GC in the CLR, but what about unmanaged languages)?
-
Can someone explain to me the lifetime of a static member variable? That is, in a singleton, one has a static member variable of the single instance and a static member function which returns a reference to that instance. How is it that, 1) the static member variable is maintained, 2) the static member variable is destroyed (GC in the CLR, but what about unmanaged languages)?
You will need to count the references created to it, and if none is needed anymore, the unmanaged resources can be released. By design a static member will instantiate whenever it is first accessed and will last the lifetime of the appdomain. There is no GC on those objects AFAIK.