6
Reply

Drawing and out of memory exceptions

Box

Box

Dec 21 2011 9:44 AM
2.5k
Hi

im having some issues with memory.

I have an on paint event:

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

float mspeed = 30;

float cspeed = 180/mspeed*float.Parse(this.labSpeed.Text);

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (Pen p = new Pen(Color.Green, 30))
{
e.Graphics.DrawArc(p, 40, 20, 80, 80, 180, 180);
}
using (Pen p = new Pen(Color.Red, 20))
{
//p.Alignment = PenAlignment.Inset;
e.Graphics.DrawArc(p, 40, 20, 80, 80, 180, cspeed);
}
using (Pen p = new Pen(Color.Orange, 10))
{
//p.Alignment = PenAlignment.Inset;
e.Graphics.DrawArc(p, 40, 20, 80, 80, 180, float.Parse(this.labPB.Text)*180/mspeed);
}

}

On my timer I have a this.invalidate() to make sure tis called but am getting out of memory errors. the faster the ticker is going the sooner the error so im guessing theres some kind of memory leak. is there a way to clear this up or release what ever is being used?

I've done lots of searching but it appears this out of memory expection is thrown up for all kinds of errors :/

Answers (6)