Two JNI init functions store jniHelperClass and mainActivityObj with NewGlobalRef, then overwrite those same globals on the next call. The previous refs are never released. This file has no DeleteGlobalRef and no JNI_OnUnload.
Where
app/src/main/cpp/libUvc_Support/libuvc_support.c (d035099)
- Lines 1041–1042:
JniPrepairStreamOverSurfaceUVC creates both global refs
- Lines 1053–1054:
JniWebRtcJavaMethods creates both global refs again
- Both write the same two globals declared at lines 158–159
What leaks
A second call, or a call to the other entry, replaces jniHelperClass and mainActivityObj without DeleteGlobalRef on the old values. Those refs stay in the global reference table. mainActivityObj is not read again in this file, so it only keeps the Java object alive.
Holding one global ref until process exit is a normal callback cache. The bug is the overwrite, and the lack of a matching DeleteGlobalRef when streaming stops or the library unloads.
Suggested fix
Before each assignment, delete the existing ref if it is non-NULL. Delete both refs when the capture stops, and in JNI_OnUnload.
Two JNI init functions store
jniHelperClassandmainActivityObjwithNewGlobalRef, then overwrite those same globals on the next call. The previous refs are never released. This file has noDeleteGlobalRefand noJNI_OnUnload.Where
app/src/main/cpp/libUvc_Support/libuvc_support.c(d035099)JniPrepairStreamOverSurfaceUVCcreates both global refsJniWebRtcJavaMethodscreates both global refs againWhat leaks
A second call, or a call to the other entry, replaces
jniHelperClassandmainActivityObjwithoutDeleteGlobalRefon the old values. Those refs stay in the global reference table.mainActivityObjis not read again in this file, so it only keeps the Java object alive.Holding one global ref until process exit is a normal callback cache. The bug is the overwrite, and the lack of a matching
DeleteGlobalRefwhen streaming stops or the library unloads.Suggested fix
Before each assignment, delete the existing ref if it is non-NULL. Delete both refs when the capture stops, and in
JNI_OnUnload.