Yes, that is correct. In this 'rendering loop' we recycle our control for performance reasons before rendering the next item on the list. So we need to reset the chart to the original state before continuing.
In our 'loop' we call a Render method - and I have wrapped this call with a call to GetGuiResources through pinvoke. like so:
Debug.WriteLine(string.Format("User Handle count before Render: {0}", GetUserObjectCount().ToString()));
renderer.Render(this, control, this.resultStream);
Debug.WriteLine(string.Format("User Handle count after Render: {0}", GetUserObjectCount().ToString()));
where GetUserObjectCount is defined as such:
private int GetUserObjectCount()
{
return Convert.ToInt32(GetGuiResources(Process.GetCurrentProcess().Handle, GR_USEROBJECTS));
}
private const uint GR_USEROBJECTS = 1;
[DllImport("User32.dll")]
static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
Here I can clearly see that the delta between before and after is 1 (increasing). Stepping through the 'Render' code reveal the increase in count specifically when calling:
m_chart.Reset();
where m_chart is a WinForms.Chart object, and I can verify this further by wrapping this line with the same call to GetGuiResources.
In fact, if I specifically remove the call to reset the chart above, then the leak disappears. However doing so affects our performance so we need to have the reset there.