Object Structure, Lifetime, and Disposal
This topic provides information about the following:
OCR API Object Structure
The OCR API uses a simple object structure with two top-level objects:
- The ImGearOCR Object - The ImGearOCR object represents the recognition engine. When this object is instantiated, the native recognition engine is initialized. The recognition engine will remain initialized until:
- All references to each ImGearOCR object instance and any associated objects cease to exist and garbage collection occurs, or
- The application calls the Dispose method for each ImGearOCR instance.
The Dispose method lets the application shut down the recognition engine immediately, freeing its resources. The application cannot use the recognition engine after having called the Dispose method. It is acceptable to instantiate a new ImGearOCR object afterwards and use that object.
- The ImGearOCRPage Object - The ImGearOCRPage object represents a page with associated image and recognition data. This object can only be instantiated by the ImportPage method of ImGearOCR. Resources associated with an ImGearOCRPage object will continue to be in use until:
- All references to the ImGearOCRPage object and any associated child objects (i.e., not ImGearOCR) cease to exist and garbage collection occurs, or
- The application calls the Dispose method.
The Dispose method lets the application free resources associated with the ImGearOCRPage object. In order to minimize resource usage, it's recommended to explicitly call this Dispose method whenever an ImGearOCRPage object is no longer needed by the application. The application cannot use an ImGearOCRPage object or its associated child objects after having called its Dispose method.
Visual representation of the hierarchy:
Engine (ImGearOCR)
Page (ImGearOCRPage)
Common Reasons to Call the Dispose Method
Under normal circumstances an application is not required to call a Dispose method. The most common reasons to call this method are:
- To minimize memory usage by disposing of ImGearOCRPage objects that are no longer needed.
- To be able to shut down and re-initialize the recognition engine.