G
Guest
The following code leaks a ton of GDI handles despite Disposing of the
related Region objects:
private void Form1_Paint(object sender, PaintEventArgs e)
{
Region region = null;
try
{
VisualStyleRenderer renderer =
new VisualStyleRenderer(
VisualStyleElement.Button.PushButton.Normal.ClassName,
VisualStyleElement.Button.PushButton.Normal.Part,
2);
region = renderer.GetBackgroundRegion(e.Graphics,
ClientRectangle);
}
catch (Exception x)
{
timer1.Enabled = false;
Trace.WriteLine(x.ToString());
}
finally
{
if (region != null)
region.Dispose();
}
}
Am I completely brain dead and this is wrong or is it a bug as I suspect? If
I create the Region objects myself all is well and there is no leak, but if I
rely on the VisualStyleRenderer object to give me the Region it leaks like a
sieve.
Note: the aforementioned code is obviously horribly incomplete. This was the
smallest 'safe' example I could come up with however that illustrates the
problem in a paint method.
Any info or guidance would be appreciated.
related Region objects:
private void Form1_Paint(object sender, PaintEventArgs e)
{
Region region = null;
try
{
VisualStyleRenderer renderer =
new VisualStyleRenderer(
VisualStyleElement.Button.PushButton.Normal.ClassName,
VisualStyleElement.Button.PushButton.Normal.Part,
2);
region = renderer.GetBackgroundRegion(e.Graphics,
ClientRectangle);
}
catch (Exception x)
{
timer1.Enabled = false;
Trace.WriteLine(x.ToString());
}
finally
{
if (region != null)
region.Dispose();
}
}
Am I completely brain dead and this is wrong or is it a bug as I suspect? If
I create the Region objects myself all is well and there is no leak, but if I
rely on the VisualStyleRenderer object to give me the Region it leaks like a
sieve.
Note: the aforementioned code is obviously horribly incomplete. This was the
smallest 'safe' example I could come up with however that illustrates the
problem in a paint method.
Any info or guidance would be appreciated.