From b6f74357e01c289d97e3afa2dbc46bce45d7cca8 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 19 Apr 2017 14:28:17 +0200 Subject: [PATCH] delete JNI weak refs when the java object (LinphoneFriend or LinphoneChatMessage) is finalized. This will avoid a periodic weak ref overflow. --- coreapi/linphonecore_jni.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index d757b7a70..cd4dc2163 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -4191,7 +4191,11 @@ extern "C" void Java_org_linphone_core_LinphoneFriendImpl_finalize(JNIEnv* env ,jobject thiz ,jlong ptr) { LinphoneFriend *lfriend=(LinphoneFriend*)ptr; + jobject wref = (jobject)linphone_friend_get_user_data(lfriend); linphone_friend_set_user_data(lfriend,NULL); + if (wref){ + env->DeleteWeakGlobalRef(wref); + } linphone_friend_unref(lfriend); } @@ -4727,7 +4731,11 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setListener(JNIEn extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_unref(JNIEnv* env ,jobject thiz ,jlong ptr) { + jobject wref = (jobject)linphone_chat_message_get_user_data((LinphoneChatMessage*)ptr); linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr, NULL); + if (wref){ + env->DeleteWeakGlobalRef(wref); + } linphone_chat_message_unref((LinphoneChatMessage*)ptr); }