TreeNodes don't get collected with weakevent solution
Posted
by Marcus
on Stack Overflow
See other posts from Stack Overflow
or by Marcus
Published on 2010-06-09T12:40:28Z
Indexed on
2010/06/09
12:42 UTC
Read the original article
Hit count: 312
Hi,
When I use this method http://stackoverflow.com/questions/1089309/weak-events-in-net (by Egor) to hook up a event i a inherited treenode, the tree node never gets collected, is there any speciall case with tree nodes and GC?
public class MyTreeNode : TreeNode
{
public MyTreeNode(Entity entity)
{
entity.Children.ListChanged += new ListChangedEventHandler(entityChildren_ListChanged).MakeWeak(eh => entity.Children.ListChanged -= eh);
}
}
Entity.Children is a bindinglist.
I made tests with a destructor on MyTreeNode and invoking GC.Collect(), with the weak eventhandler the treenode never gets collected but i DOES get collected WIHTOUT the weak eventhandler.
© Stack Overflow or respective owner