Open sandboxFocus

Property WeakEventStrategy

WeakEventStrategy

Determines how the PropertyChanged event behaves in terms of keeping weak or strong references.

Declaration
public WeakEventStrategy WeakEventStrategy { get; set; }
Property Value
Type Description
WeakEventStrategy
Remarks

Setting this property to Default is equivalent to AlwaysWeak.

Setting this property to AlwaysWeak forces the event to hold only weak references. A ConditionalWeakTable<TKey, TValue> is used to bind the lifetime of the delegate to it's target even if registering object does not keep a reference to the delegate. This does not prevent the target object from being collected along with the delegate, which may happen implicitly when a lambda or local function with a closure is used as an event handler. In this case, there is no reference to the closure class retained.

Setting this property to AlwaysStrong forces the event to hold only strong reference. This may prevent components that do not support weak event behavior to have subscribed delegates collected. However, it may cause memory leaks if delegates are not unregistered from the event.