There's a problem when I use Halcon operator find_model_shape in C#. The memory occupied by this operator cannot be released even if using clear_shape_model as Halcon says.
It seems like the memory occupied by find_shape_model is larger when the more complicated shape searching parameters are set to be.
I just want to know how to release the memory after using this operator.
private void button1_Click(object sender, EventArgs e)
{
HTuple hv_ModelId = null;
HTuple hv_ModelRow = null;
HTuple hv_ModelColumn = null;
HTuple hv_ModelAngle = null;
HTuple hv_ModelScore = null;
HObject ho_Image = null;
HOperatorSet.GenEmptyObj(out ho_Image);
ho_Image.Dispose();
HOperatorSet.ReadImage(out ho_Image, "0.bmp");
HOperatorSet.SetSystem("border_shape_models", "false");
HOperatorSet.ReadShapeModel("0.shm", out hv_ModelId);
HOperatorSet.FindShapeModel(ho_Image, hv_ModelId, 0,
3.14, 0.75, 0, 0.5, "least_squares", 6, 0.75, out hv_ModelRow,
out hv_ModelColumn, out hv_ModelAngle, out hv_ModelScore);
hv_ModelRow = null;
hv_ModelColumn = null;
hv_ModelAngle = null;
hv_ModelScore = null;
ho_Image.Dispose();
HOperatorSet.ClearShapeModel(hv_ModelId);
hv_ModelId = null;
}
Memory before/after using find_shape_model
It looks like you are clearing the shape model correctly using the function:
HOperatorSet.ClearShapeModel(hv_ModelId);
Are you sure the memory is not released? What happens if you read the same shape-model again after you cleared the memory?
HOperatorSet.ReadShapeModel("0.shm", out hv_ModelId);
I would wager that the memory is not affected. Basically how the memory is managed also depends on your OS. Your OS may not immediately give the memory to other processes because it expects that the memory may be used again.
Just out of curiosity: which OS are you using and how did generate the graph in your screenshot?
This seems similar to this problem.
Have you tried this?
GC.Collect();
GC.WaitForPendingFinalizers();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With