In C #, I'm used to clearing every subscription to my user events in Dispose()to avoid memory leaks for subscribers forgetting to unsubscribe from my events.
This was very simple to do, just by calling MyEvent = null, as the C # compiler automatically generates a delegate field. Unfortunately, in VB.NET, there seems to be no easy way to do this. The only solution I came across was writing Custom Event, adding custom add and remove handlers that call Delegate.Combine/ Delegate.Remove, mainly what the C # compiler does. But doing it for every event, just to clear my subscriptions, seems a bit "redundant" to me.
Does anyone have any other idea to solve this problem? Thanks.
source
share