5

I'm after a good implementation of the weak event patterns for Silverlight to avoid memory leaks. There seem to be a few implementations out there but the code is not trivial and it's hard to know which one is correct. I can't find any official recommendation from Microsoft.

I'm after a simple syntax if possible.

Cheers.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Clement
  • 3,990
  • 4
  • 43
  • 44

1 Answers1

4

Install a copy of the Silverlight Toolkit which comes with source code zipped up. In there you will find the pattern of weak events that you might consider the "Microsoft" recommendation. (You can also fetch the latest source from codeplex).

The implementation you are after is WeakEventListener found in the Common folder of he main Controls.Toolkit project.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Nice and clean. Although it seems that it does not properly protect against non-static handlers, which can be auto generated by the compiler when using lamdas. This post explains the issue: http://blog.thekieners.com/page/3/ Is that a bug in the SL toolkit implementation ? – Clement Nov 15 '11 at 21:58
  • @Clement: to which specific blog entry are you refering? – AnthonyWJones Nov 15 '11 at 22:10
  • Sorry, this one: http://blog.thekieners.com/2010/02/11/simple-weak-event-listener-for-silverlight/ – Clement Nov 15 '11 at 23:34