Use this forum to discuss subjects that don't belong in the other forums.
- Posts: 4
- Joined: Sat Jan 22, 2011 5:14 am
I keep getting MemProfiler reporting that I don't unsubscribe from events. The thing is that our code in VB.NET has the "Handles <EventXXX>" clause on some methods and it looks like that is what MemProfiler is reporting as a leak. When does the "Handles" clause unsubscribe? Why is MemProfiler reporting this as a leak?
- Posts: 1000
- Joined: Wed Mar 02, 2005 7:53 pm
The Handles clause will never unsubscribe, but normally this is not a problem. If the Handles clause is added by a form designer, the subscriber and the event source usually have the same life time. For instance, a Form might handle a button event and when the form is closed, both the form and the button will be eligible for garbage collection. In this case, there's no need to remove the handler. On the other hand, if the event source has a longer lifetime than the subscriber, then the event handler must be removed manually by using the RemoveHandler keyword.
.NET Memory Profiler will give you information about event handlers that solely responsible for keeping an instance alive, as this is a common cause of memory leaks (but definitely not a certain memory leak).
What kind of issue does the profiler report?
SciTech Software AB
Users browsing this forum: Google [Bot] and 6 guests