Skip to content

docs: document memory ownership and lifecycle in C-API#4511

Merged
stweil merged 1 commit intotesseract-ocr:mainfrom
markbus-ai:fix/docs-capi-memory-management
Feb 13, 2026
Merged

docs: document memory ownership and lifecycle in C-API#4511
stweil merged 1 commit intotesseract-ocr:mainfrom
markbus-ai:fix/docs-capi-memory-management

Conversation

@markbus-ai
Copy link
Contributor

The current C-API documentation in capi.h is insufficient regarding memory management and object lifecycle, often leading to memory leaks or segmentation faults when implemented in C or via FFI (like Python's ctypes).

This PR updates the Doxygen comments to:

  • Clarify Memory Ownership: Explicitly state that functions returning char* (such as TessBaseAPIGetUTF8Text, TessBaseAPIGetHOCRText, TessBaseAPIGetAltoText, etc.) return newly allocated memory that must be freed by the caller using TessDeleteText().
  • Define Object Lifecycle: Added a clear, step-by-step lifecycle guide in the TessBaseAPICreate() documentation to help developers understand the mandatory sequence (Create -> Init -> SetImage -> Process -> Delete).
  • Leptonica Integration: Clarified that TessBaseAPISetImage2() does NOT take ownership of the Pix structure, and the caller remains responsible for calling pixDestroy().
  • Initialization Details: Added information about TessBaseAPIInit3() behavior when datapath is NULL.

These changes improve the developer experience and system stability for anyone using the Tesseract C-API.

Copy link
Member

@stweil stweil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@stweil stweil merged commit c9a0fb9 into tesseract-ocr:main Feb 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants