开发环境:Win7 VS2002 halcon12, 直接运行Debug的exe
private void butTemp_Click(object sender, EventArgs e)
{
HOperatorSet.SetSystem("clip_region", "false");
HObject region;
HOperatorSet.GenEmptyRegion(out region);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 10000; j++)
{
HObject tmpRegion;
HOperatorSet.GenRectangle1(out tmpRegion, i, j, i, j);
HOperatorSet.Union2(tmpRegion, region, out region);
}
HTuple tArea, tmp;
HOperatorSet.AreaCenter(region, out tArea, out tmp, out tmp);
Debug.Assert(tArea > 0);
TestForm form = new TestForm();
form.ShowDialog();
}
不到一分钟运行结束,最多占用1G内存,运行结束占用800M内存。
private void butTemp_Click(object sender, EventArgs e)
{
HOperatorSet.SetSystem("clip_region", "false");
HObject region;
HOperatorSet.GenEmptyRegion(out region);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 10000; j++)
{
HObject tmpRegion;
HOperatorSet.GenRectangle1(out tmpRegion, i, j, i, j);
HOperatorSet.Union2(tmpRegion, region, out region);
tmpRegion.Dispose();
}
HTuple tArea, tmp;
HOperatorSet.AreaCenter(region, out tArea, out tmp, out tmp);
Debug.Assert(tArea > 0);
TestForm form = new TestForm();
form.ShowDialog();
}
不到一分钟运行结束,最多占用0.5G内存,运行结束占用0.5G 内存。
private void butTemp_Click(object sender, EventArgs e)
{
HOperatorSet.SetSystem("clip_region", "false");
HObject region;
HOperatorSet.GenEmptyRegion(out region);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 10000; j++)
{
HObject tmpRegion;
HOperatorSet.GenRectangle1(out tmpRegion, i, j, i, j);
HOperatorSet.Union2(tmpRegion, region, out region);
tmpRegion.Dispose();
}
HTuple tArea, tmp;
HOperatorSet.AreaCenter(region, out tArea, out tmp, out tmp);
Debug.Assert(tArea > 0);
region.Dispose();
TestForm form = new TestForm();
form.ShowDialog();
}
几乎没变化,还是0.5G左右
private void butTemp_Click(object sender, EventArgs e)
{
HOperatorSet.SetSystem("clip_region", "false");
HObject region;
HOperatorSet.GenEmptyRegion(out region);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 10000; j++)
{
HObject tmpRegion;
HOperatorSet.GenRectangle1(out tmpRegion, i, j, i, j);
HObject bak = region;
HOperatorSet.Union2(tmpRegion, region, out region);
bak.Dispose();
tmpRegion.Dispose();
}
HTuple tArea, tmp;
HOperatorSet.AreaCenter(region, out tArea, out tmp, out tmp);
Debug.Assert(tArea > 0);
region.Dispose();
TestForm form = new TestForm();
form.ShowDialog();
}
不到一分钟运行结束,内存几乎没增加,不到20M以内。
Union2的出参和入参一致时,必须手动释放,这样才能100% 马上回收内存。