views:

28

answers:

1

I am dynamically building an org chart in Silverlight 2 by adding lots of Grid containers to a canvas. Each grid container represents a node within the chart. I am capturing click events for the nodes as follows:

grid.MouseLeftButtonUp += new MouseButtonEventHandler(grid_MouseLeftButtonUp);

By design, each click event changes the look of the tree, so on capturing a click event I rebuild the entire org tree. This works ok for two or three clicks, but after that everything just hangs when I click a node (Grid). Each time I rebuild the tree I clear the base canvas using:

_canvasBase.Children.Clear();

I am wondering if I need to specifically clear all the event delegates before clearing all the canvas children? Or might something else be happening to cause the hang?

+1  A: 

Yes you will be leak memory badly if you do not remove the event handlers.

AnthonyWJones
Thanks - can you advise on the best way to remove all subscribed handlers for a particular uielement? In the code I will not actually know which handlers are linked up to each element.
DEH