MemProfiler and VB.NET Handles clause

Use this forum to discuss subjects that don't belong in the other forums.

Moderator: SciTech Software

MemProfiler and VB.NET Handles clause

Postby sparky2708 » Tue Jul 26, 2011 6:43 pm

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?
sparky2708
 
Posts: 4
Joined: Sat Jan 22, 2011 5:14 am

Re: MemProfiler and VB.NET Handles clause

Postby Andreas Suurkuusk » Wed Jul 27, 2011 1:20 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?
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 963
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

SciTech Software logo

© Copyright 2001-2016. SciTech Software AB
All rights reserved.


SciTech Software AB
Kartvägen 21
SE-175 46 Järfälla
Sweden


E-mail: mail@scitech.se

Telephone: +46-706868081

cron