Memory Leak on Datagridview

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Posts: 1
Joined: Mon Mar 31, 2008 9:20 am

Memory Leak on Datagridview

Post by andycsmith » Mon Mar 31, 2008 3:16 pm

I using the profiler to trace a memory leak we are having with our application, i'm reasonable sure I have tracked down the problem but I would like confirmation that I have interprated the results corectly.

This is what i'm getting in the Type instance details

Myriad.Controls FilterBar #61,149._cboFilterColumn
Myriad.Controls DataGridView #61,148
Microsoft.Win32 UserPreferenceChangedEventHandler #67,071._target
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo #67,072._delegate
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo[] #60,685
System.Collections.Generic List<SystemEvents.SystemEventInvokeInfo> #6,591._items
System.Collections.Generic Dictionary<object, List<SystemEvents.SystemEventInvokeInfo>>.Entry[] #6,531[2].value
System.Collections.Generic Dictionary<object, List<SystemEvents.SystemEventInvokeInfo>> #6,533.entries
Microsoft.Win32 SystemEvents _handlers

Double clicking on the SystemEvents.SystemEventInvokeInfo line gives me

SystemEvents.AddEventHandler(object, Delegate)
frmContactTab..ctor(int, Form)
frmContactMDI.frmContactMDI_Load(object, EventArgs)

Which to me indicates that an event handler is being added for UserPreferenceChanged, but our application does not add this event it seams to occur when changing properties on the datagrid.

Am I correct so far. I now want to remove this system event so that the object can be dispoed, i'm currently trying to use the following code in the Dispose event but it does not appear to work

Dim eventHandler As UserPreferenceChangedEventHandler = CType(System.Delegate.CreateDelegate(GetType(UserPreferenceChangedEventHandler), mDGV, "OnUserPreferenceChanged"), UserPreferenceChangedEventHandler)
RemoveHandler SystemEvents.UserPreferenceChanged, eventHandler

mDGV is the DataGridView being referenced in the control.

Can anyone give me any advice. I need to help in VB.Net code as this is what we use for our application.


Andreas Suurkuusk
Posts: 1043
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Tue Apr 01, 2008 7:00 pm

You are correct that the DataGridView is being kept in memory by the UserPreferencesChanged event, but I don't see that it should occur when changing properties on the datagrid. The allocation call stack indicates that the event handler is added in the constructor of the DataGridView, not when changing properties.

The root path tells me that the datagrid is implemented by Myriad.Controls.DataGridView. How is this class related to the System.Windows.Forms.DataGridView? Is it derived from the WinForms class? As far as I could see, the System.Windows.Forms.DataGridView does not add any event handlers to UserPreferencesChanged in the constructor, so I assume that the DataGridView in the allocation stack is the Myriad.Controls.DataGridView. Is that correct?

Without knowing more about the implementation of Myriad.Controls.DataGridView it's hard to tell why your fix doesn't work. Are you sure the event handler is hooked to the "OnUserPreferencesChanged" method?
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests