PostSharp6.0/API Reference/Post­Sharp.​Patterns.​Model Namespace/Notify­Property­Changed­Attribute Class/Notify­Property­Changed­Attribute Properties/Notify­Property­Changed­Attribute.​Weak­Event­Strategy Property

NotifyPropertyChangedAttribute.WeakEventStrategy Property

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

Namespace:  PostSharp.Patterns.Model
Assembly:  PostSharp.Patterns.Model (in PostSharp.Patterns.Model.dll) Version: 6.1.6.0 (6.1.6.0)
Syntax
C#
public WeakEventStrategy WeakEventStrategy { get; set; }

Property Value

Type: 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.

See Also