JNI local references accumulate during OCR result conversion
Author: QiuYucheng2003Created Sep 7, 2026Updated Sep 7, 2026
Summary
JNI local references are not released while converting OCR results to Java objects.
Key cases:
newJBoxPoint()repeatedly createsjPointreferences without releasing them afterCallBooleanMethod.getTextBlocks()repeatedly createsjTextBlockreferences without releasing them after insertion into the list.- Temporary references such as
clazz,jText,jCharScores, andjBoxPintare also retained until the outer JNI method returns.
C++ helper functions share the caller's JNI local reference frame. Returning from these helpers does not release their local references, and adding an object to a Java list does not consume its JNI reference.
Impact
OCR results containing many text blocks or points can continuously grow the JNI local reference table, potentially causing table overflow, initialization failure, or an application crash.
Suggested fix
Call DeleteLocalRef after each temporary reference is no longer needed, especially jPoint and jTextBlock inside loops. Alternatively, manage each conversion scope with PushLocalFrame / PopLocalFrame.
Source: DayBreak-u/chineseocr_lite