Skip to content

Theraot.Collections.ThreadSafe.WeakEvent

Alfonso J. Ramos edited this page Nov 10, 2015 · 4 revisions

WeakEvent<TEventArgs>

When creating an event in .NET what you are actually doing is creating a list of delegates to be called. This means that wherever you have an event, you also are keeping references to all the subribed methods and objects... that will prevent them to be garbage collected...

Instead you could use WeakReference to keep track of the delegates. This is what WeakEvent is here to solve.

In addition to the benefits of WeakDelegateCollection, WeakEvent provides a simple and easy to use interface to provide weak events.