[IronPython] static source2handler mapping causing memory leaks

Kamil Dworakowski kamil at dworakowski.name
Tue Dec 18 10:32:01 CET 2007

I think I have found what is a design flaw in implementation of events 
in IronPython that causes memory leaks. This seems to affect both IP 1.1 
and IP 2.

As far as I understand the code of IP, 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 ;).

Why not make values of the mapping weak references too?

Kamil Dworakowski
Resolver Systems

More information about the Ironpython-users mailing list