Hey guys,
I was always under the impression that routed events follow the weak event pattern... today I am doing some stuff and I found out that they are not. Looked up in reflector and found out this
It's actually keeping a striong reference to the handler.
I tried something out and it is true objects don't get GCed
// Add 1000 objects. If routed events are "weak" thiese will get garbage
// collected afterwards
for (int i = 0; i < 1000; i++)
{
TestObject o = new TestObject();
// The below line causes the memory leak
((Button)sender).Click += o.Handler;
}
// o should be finalized here
GC.Collect();
Am I missing something?
Regards
Marlon
WPF Blog -
http://marlongrech.wordpress.com/Microsoft MVP for Client App