Sunday, September 2, 2012

Silverlight event delegates

Silverlight event delegates

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?

Answers & Comments...

Answer: 1

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

by : AnthonyWJoneshttp://stackoverflow.com/users/17516




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog