1. HObject HRegion HImage对象
(1)可以直接new一个对象,但该对象是没有初始化的(即IsInitialized为false);
摘录说明(1):
a.
In addition, all classes have empty constructors to create an uninitialized object....
...If the instance was already initialized, the corresponding data structures are automatically destroyed before constructing and initializing them anew;
所有利用空构造函数构建的类对象都是未初始化的;如果已经初始化的对象,则对应的构造函数会把它给先释放,然后再重新构造新的。
b. 过程接口的HOperatorSet.GenEmptyObj比单纯new一个对象添加更多的附加判定,包括预先调用的错误码判定,然后调用new,在调用后会从一个指定的指针处进入Halcon自己的内存管理控制。
(2)对象用完之后需要Dispose
摘录说明(1):
Please note that HALCON operators always create a new object instance for output parameters and return values;
halcon每次使用算子时,对输出变量或者返回值都会创造一个新的变量,所以使用变量的时候,需要将变量原来的数据给dispose掉;除了一些类似构造对象的算子,就可以不用预先Dispose;
如
HImage img = new HImage();
img.ReadImage("xxx");
摘录说明(2):
Please note that HALCON operators always create a new object instance for output parameters and return values (but not in the “constructor-like” operator calls that modify the calling instance). If the variable was already initialized, its old content (and the memory allocated for it) still exists until the garbage collector removes it. If you want to remove it manually, you must call Dispose before assigning an object to it.
(3)CopyObj和Clone的区别
CopyObj只是引用增加,而Clone是深拷贝;Dispose会释放引用,假如一个对象没有引用了,则会释放内存,故在进行内存管理时,多数情况下会采用CopyObj;
2. HTuple变量
初次使用需要new;用完后要Dispose;
注意:每次赋值前需要Dispose;以out参数的方式从方法中获取返回值,在使用前也需要Dispose;