GC and self-referencing events

  • Thread starter Thread starter Uwe Hafner
  • Start date Start date
U

Uwe Hafner

Hi,

1.
if an event is added a method in the same class like:

this.myevent += new MyEventHandler(this.DoMyEvent);

this would be a pointer to a method in my own class.
Does this prevent GC from collecting the object if it is the only reference
left? Or does the GC not count this reference of the object to a method in
itself?

I would expect the GC to still collect the object. Can someone confirm this?

2.
Is there a tool I can use for monitoring my objects if they are GCed
correctly (where I can explicitly track definite instances of a class) ?

Thanks
Uwe
 
Uwe,
Does this prevent GC from collecting the object if it is the only reference
left?
No


Or does the GC not count this reference of the object to a method in
itself?

It's able to handle self references and circular references, yes.



Mattias
 
The reference would not be accessible from a root level object. The GC does
not use reference counters. It checks which objects are currently
inaccessible from code.

J. Tennyson Einstein
Einstein Technologies
http://www.einsteinware.com
 
Back
Top