saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
2.99k stars 1.2k forks source link

memory leak when repeat open close camera #518

Open YiZhou213 opened 4 years ago

YiZhou213 commented 4 years ago

After Modify ---void UVCPreview::do_capture_callback(JNIEnv env, uvc_frame_t frame) { ENTER();if (LIKELY(frame)) { uvc_frame_t *callback_frame = frame; if (mFrameCallbackObj) { if (mFrameCallbackFunc) { callback_frame = get_frame(callbackPixelBytes); if (LIKELY(callback_frame)) { int b = mFrameCallbackFunc(frame, callback_frame); recycle_frame(frame); if (UNLIKELY(b)) { LOGW("failed to convert for callback frame"); goto SKIP; } } else { LOGW("failed to allocate for callback frame"); callback_frame = frame; goto SKIP; } } jobject buf = env->NewDirectByteBuffer(callback_frame->data, callbackPixelBytes); pthread_mutex_lock(&capture_mutex); if(iframecallback_fields.onFrame != NULL){ env->CallVoidMethod(mFrameCallbackObj, iframecallback_fields.onFrame, buf); } pthread_mutex_unlock(&capture_mutex); env->ExceptionClear(); env->DeleteLocalRef(buf); }

And void UVCPreview::addCaptureFrame(uvc_frame_t *frame) { } captureQueu = frame; pthread_cond_broadcast(&capture_sync); } else { // Add this can sovle native leak recycle_frame(frame); }

pthread_mutex_unlock(&capture_mutex);

}

My native heap also keeps rising and can't be released.