This project has moved. For the latest updates, please go here.


Event handlers can cause circular references and leak memory


<Thanks>Kamil Dworakowski</Thanks>
<Test> (test_event_lifetime)</Test>
there is an instance of ReflectedEvent per event in a class (making it effectively static). This ReflectedEvent object holds a hashtable from source of the event to a handler. This hashtable is of class WeakHash in which keys are weak references but the values are strong references.
There is a problem only for cases where GC can reach the source (the
key) by references starting from the handler (the value). This means that values are keeping the keys alive and they will live happily ever after just for themselves (and all their extended family, meaning the objects that can be reach from them ;).
Closed Mar 5, 2008 at 2:05 AM by dfugate