Halcon的内存管理

5.4Memory Management
All of HALCON's classes, i.e., not only HImage, HRegion, HTuple, HFramegrabber etc., but also the class HObject used when calling operators in the procedural approach, release their allocated resources automatically in their destructor (see also section “Destructors and Halcon Operators”).
Furthermore, when constructing instances anew, e.g., by calling CreateBarCodeModel via an already initialized instance as mentioned in section “Constructors and Halcon Operators”, the already allocated memory is automatically released before reusing the instance. Thus, there is no need to call the operator ClearObj in HALCON/C++; what is more, if you do use it HALCON will complain about already released memory.
To explicitly release the resources before the instance gets out of scope, you can call the method Clear() of the instance.
However, there is one occasion for explicit memory management on your part: This applies when using handles in the procedural approach: The memory allocated when creating a handle, e.g., with OpenFramegrabber, is only released when calling the “complementary” operator, in the example CloseFramegrabber — or at the end of the program.

5.2.4Destructors and Halcon Operators
All HALCON/C++ classes provide default destructors which automatically free the corresponding memory. For some classes, the destructors are based on suitable operators:
Windows:
The default destructor of the class HWindow closes the window based on CloseWindow. Note that the operator itself is no destructor, i.e., you can close a window with CloseWindow and then open it again using OpenWindow.
Other Handle Classes:
The default destructors of the other classes encapsulating handles, e.g., HShapeModel or HFramegrabber, apply operators like ClearShapeModel or CloseFramegrabber, respectively. In contrast to CloseWindow, these operators cannot be called via instances of the class, as can be seen in the corresponding reference manual entries; the same holds for operators like ClearAllShapeModels. In fact, there is no need to call these operators as you can initialize instances anew as described in section “Constructors and Halcon Operators”.
Please note that you must not use operators like ClearShapeModel, ClearAllShapeModels, or CloseFramegrabber together with instances of the corresponding handle classes!
"temporary_mem_cache" *), "tsp_temporary_mem_cache"
This parameter controls the operating mode of the temporary memory cache. The temporary memory cache is used to speed up an application by caching memory used temporarily during the execution of an operator. For most applications the default setting ("exclusive") will produce the best results. The following modes are supported:
"idle" The temporary memory cache is turned off. This mode will use the least memory, but will also reduce performance compared to the other modes.
"shared" All temporary memory is cached globally in the temporary memory reservoir. This mode will use less memory than "exclusive" mode, but will also generally offer less performance.
"exclusive" All temporary memory is cached locally for each thread. This mode will use the most memory, but will generally also offer the best performance.
"aggregate" Temporary memory blocks that are larger than the threshold set with the "alloctmp_max_blocksize" parameter are cached in the global memory reservoir, while all smaller blocks are aggregated into a single block that is cached locally for each thread. If the global memory reservoir is disabled, the large blocks are freed instead. The aggregated block will be sized according to the temporary memory usage the thread has seen so far, but it will not be larger than "alloctmp_max_blocksize" (if set) or smaller than "alloctmp_min_blocksize" (if set). This mode balances memory usage and speed, but requires correctly setting "alloctmp_min_blocksize" and "alloctmp_max_blocksize" for the application's memory usage pattern for effectiveness.
Note that cache mode "idle" is set in exclusive run mode, whereas the other modes are set in reentrant mode.
For backward compatibility, the values "false" and "true" are also accepted; they correspond to "idle" and "exclusive", respectively.
Value: "idle", "shared", "exclusive", or "aggregate"
【Halcon的内存管理】Default: "exclusive"

    推荐阅读