Aspect that, when applied to an event, prevents the target event from holding a strong reference to event handlers. Therefore, the aspect prevents the event from preventing clients from being garbage collected.
Inheritance
Implements
Namespace: PostSharp.Patterns.Model
Assembly: PostSharp.Patterns.Model.dll
Syntax
[LinesOfCodeAvoided(6)]
[Serializer(typeof(WeakEventAttribute.Serializer))]
public sealed class WeakEventAttribute : EventInterceptionAspect, IEventLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IEventInterceptionAspect, IEventLevelAspect, IInstanceScopedAspect, IAspectRemarks
Event clients do not need to keep a strong reference to the delegates passed to a weak event. The WeakEventAttribute implementation will keep delegate instances alive as long as the event client (that is, the object that the Target property points to) is alive, but no longer.
Clients do not need to unregister their handlers, or implement IDisposable to do it, unless the handler must stop receiving events before the client is garbage collected.
To make all events of an assembly or a namespace weak, apply this attribute at assembly level and use attribute multicasting.
Constructors
| Name | Description |
|---|---|
| WeakEventAttribute() | Initializes a new instance of the WeakEventAttribute class. |
| WeakEventAttribute(PortableFormatterConstructorContext) |