I hope someone else will correct me if I an incorrect on something.
As part of the overhead of a managed object instance is a pointer to a
MethodTable. The method table is loaded once per type, so 50 instances of
class foo will all point to the same location. The MethodTable is
considered a root as far as garbage collection is concerned.
Inside this MethodTable are all the static types and declarations. So in
your example, in the MethodTable of your class foo, is a field called
SqlParser. SqlParser, when allocated, sits in the same managed heap as all
other objects created. (Unless it is a large object then sits in the Large
Object Heap). When the garbage collection runs, it walks the pointers from
the MethodTable finding a reference the SqlParser sitting in the regular old
heap, marks it as visited and leaves it alone.
MethodTables are never destroyed except when an AppDomain is unloaded, so
there is no way to "collect" a static variable without setting it to null,
and releasing the reference.
On a side note, since there is one MethodTable for every type loaded, if you
defined 7 bagillion of your own types and use them all, your MethodTable
"Heap" (I can't remember what it is called) will get very large, and since
it never purges itself...well you can picture the memory usage growing....
HTH,
bill
<pi****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Yeah it does make sense. I understand what you are saying. And I think
I am clear.
I am not associating static fields with the object per say. However
this begs the question what happenes to static fields when they are
created created if they are not assoiciated directly to the object that
contains them. Am I to understand that there are stored in seperate
heap space then then object itself?
Take for example this sample class of a non thread safe sigleton =-)
Now this composite static object is created on the first call to
getSQLParser that will in turn create the compsite static object. Is
this composite object then put on the heap with all others?
Public class foo{
private static SQLParser sqlParser;
public static SQLParser getSQLParser(String inURL)
{
if(sqlParser == null)
{
sqlParser = new SQLParser(inURL);
}
return sqlParser;
}
}
Thanks alot your last post it really helped.
Brette