Skip to content

Instantly share code, notes, and snippets.

@mfakane
Created February 4, 2012 22:02
Show Gist options
  • Save mfakane/1740517 to your computer and use it in GitHub Desktop.
Save mfakane/1740517 to your computer and use it in GitHub Desktop.
An implemention of WeakEvent pattern for WPF/Silverlight/Windows Phone
----
Using the Model-View-ViewModel pattern, you always need to keep your events clean when they are not used.
In example, if the object "Foo" handles an event, when you finished using the Foo and forgot to release the event handlers,
the event would keep grabbing references to the Foo. This means that a memory leak is happening.
This page would be helpful:
Weak Event Patterns
http://msdn.microsoft.com/en-us/library/aa970850.aspx
The following code is a sample implemention which can be used in WPF, Silverlight, or Windows Phone 7.
This is actually used in the "Livet" MVVM Framework, powered by Japanese MVVMers.
<<code>>
If you have any problems, suggestions, or improvements on this code, feel free to leave a comment here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment