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 :/
Loading
BoxPosted Dec 22, 2011, 10:19 AM
VulpesPosted Dec 22, 2011, 5:36 AM
http://stackoverflow.com/questions/3665206/why-is-my-c-sharp-paint-method-running-out-of-memory
So, the culprit may be a bug in the DrawArc method when using small angles though I couldn't really tell from the code how small your sweep angles were.
BoxPosted Dec 22, 2011, 4:10 AM
{
int x1 = 0;
int x2 = 0;
int y1 = 0;
int y2 = 0;
double d = 0;
double s = 0;
this.labLastX.Text = this.labXPOS.Text;
this.labLastY.Text = this.labYPOS.Text;
this.labXPOS.Text = System.Windows.Forms.Cursor.Position.X.ToString();
this.labYPOS.Text = System.Windows.Forms.Cursor.Position.Y.ToString();
this.labMouseButton.Text=Control.MouseButtons.ToString();
x1 = int.Parse(this.labLastX.Text);
x2 = int.Parse(this.labXPOS.Text);
y1 = int.Parse(this.labLastY.Text);
y2 = int.Parse(this.labYPOS.Text);
d = Math.Round(Math.Sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))),0);
this.labTickDistance.Text=d.ToString();
d += int.Parse(this.labSeshDistance.Text);
this.labSeshDistance.Text = d.ToString();
d = int.Parse(this.labSeshDistance.Text) + int.Parse(this.labPrevDistance.Text);
this.labDistance.Text = Math.Round(d/1000000,2).ToString() + "m";
q.Enqueue(d);
if (q.Count > 10)
{
s = (double)q.Dequeue();
}
else
{
s = (double)q.Peek();
}
s = d - s;
s *= 1800;
this.labPPH.Text=Math.Round(s/1000000,2).ToString() + "m";
s = Math.Round(s/456192,3);
this.labSpeed.Text = s.ToString();
if (s > double.Parse(this.labPB.Text))
{
this.labPB.Text=s.ToString();
}
d = Math.Round(d/4561920,2);
this.labMiles.Text=d.ToString();
this.notifyIcon1.Text=Math.Round(d,2).ToString() + " miles";
this.Invalidate();
}
not that I can see. I am still very new to this though so maybe? Above is my code in the ticker
VulpesPosted Dec 21, 2011, 12:02 PM
Are you creating any objects in the timer_Tick eventhandler that are not being disposed of immediately?
BoxPosted Dec 21, 2011, 10:56 AM
I tried the caching method but it still errors out.
then I tried taking out the arc. having the green and orange never errors. the red one did though. now it tends to either error right away or its fine for a while (10 mins and counting now) very puzzling -_-
VulpesPosted Dec 21, 2011, 10:03 AM