Are Classes with Static State Ever Garbage Collected ??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a low level question . . .

If I have an assembly with a single class with a static int property, I know
the assembly will get loaded the first time the class is referenced. At that
point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Thanks,

LES
 
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
 
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
 
Hi,
Through out the runtime the CLR maintains a single instance of a static
class even without the need of new so the application space remains until
app terminates
best,
Subin Kushle
 
Lester said:
I have a low level question . . .

If I have an assembly with a single class with a static int property, I know
the assembly will get loaded the first time the class is referenced. At that
point, I now have a "never been explicitly instantiated object" in memory
that can be accessed by all code that was built with a reference to the
assembly. Obviously, somewhere in the bowels of the system there is a
reference to this "never been explicitly instantiated object"

My question is, can this "object" ever get garbage collected since it came
into being without the need for "new" and there are no explicit references
that can be set to null ?? If not, then it must be destined to just waste
valuable address space until the process dies :*(

Static members are only garbage collected when the AppDomain containing
them is garbage collected. I would seriously ask yourself just how much
memory is going to be "wasted" though - chances are it's not
significant.
 
Back
Top