static fields, methods, properties ... and garbage collection

  • Thread starter Thread starter news.austin.rr.com
  • Start date Start date
N

news.austin.rr.com

are my static members of a class allocated on the stack and therfore not
subject to the grabage collection sweep and pass of the heap?
 
I guess you are asking if instances of reference types allocated in static
method are subject to garbage collection. The answer is yes.

Cheers
Daniel
 
actually im asking about the static non instance class members.

say you have a static field "static bool field1 = true;"
and static methods, properties,... in a class. do these static members get
allocated on the stack or heap.

If im not mistaken on the heap get the GC sweep and mark not the stack
 
say you have a static field "static bool field1 = true;"
Boolean is not a reference type so it will never be on the heap anyway
(unless boxing is involved). If it was something like static Object obj =
new Object() then obj would not be garbage collected since it would always
be in scope (the static class is a GC root). If you set obj to null though,
it is eligible for collection.
and static methods, properties,... in a class. do these static members get
Methods and properties are just metadata. They are not recycled once loaded
and are outside the GC scope.

Cheers
Daniel
 
Back
Top