One thing that was really unexpected for me is this:
Region oldClip = graphics.Clip;
using (Region newClip = new Region(...))
{
graphics.Clip = newClip;
// draw something
graphics.Clip = oldClip;
}
Where's the memory leak? Right, you should have disposed oldClip
, too! Because Graphics.Clip
is one of the rare properties that returns a new disposable object every time the getter is invoked.