Created
February 4, 2012 22:02
-
-
Save mfakane/1740517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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