delete JNI weak refs when the java object (LinphoneFriend or LinphoneChatMessage) is finalized.

This will avoid a periodic weak ref overflow.
This commit is contained in:
Simon Morlat 2017-04-19 14:28:17 +02:00
parent 9adce33173
commit b6f74357e0

View file

@ -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);
}