Just subscribe to a static event, or an event of a long-lived object (such as a singleton instance). That long lived object will keep alive all objects that subscribed to any of its events (including you).
You must be logged in to post a comment.
Just subscribe to a static event, or an event of a long-lived object (such as a singleton instance). That long lived object will keep alive all objects that subscribed to any of its events (including you).
You must be logged in to post a comment.
Huh, so easy… I wanna be a CLR object!
Incidentally, that's the cause of many memory leaks… I'd love a better support for weak events (or better, weak delegates) in .NET 5 ! Ideally, it could be built into the language :
public event EventHandler StrongEvent;
public event EventHandler~ WeakEvent;