c#winform,内存一直增长,直到内存溢出
static WeakReference wr = new WeakReference(null);
private void SetTheCsOnlineSight()
{
try
{
if (!isReult)
{
return;
}
IntPtr hscrdc = GetWindowDC(csHwnd);//调用api
Rectangle rect = new Rectangle();
GetClientRect(csHwnd, ref rect);//调用api获得窗口信息
Graphics g = wr.Target as Graphics; //Graphics.FromHdc(hscrdc);
int height = 0;
if (g == null)
{
g = Graphics.FromHdc(hscrdc);
wr.Target = g;
}
if (rdWindow.Checked)
{
//窗口化时需要加上任务栏高度
height = rect.Height / 2 + (Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height) + u;
}
if (rdAllScreen.Checked)
{
height = rect.Height / 2 + u;
}
g.DrawEllipse(new Pen(color), rect.Width / 2 + l, height, w, h);//准星大小
g.FillEllipse(new SolidBrush(color), (rect.Right - rect.Left) / 2 + l, height, fw, fh);//填充为实型
}
catch { }
finally
{
GC.Collect();
}
}
改成弱引用还是会内存溢出,求高手解答,在线等.