diff --git a/android/sdk/src/main/jni/src/jni/convert_utils.cc b/android/sdk/src/main/jni/src/jni/convert_utils.cc index 79a070442b0..f017df2bbba 100644 --- a/android/sdk/src/main/jni/src/jni/convert_utils.cc +++ b/android/sdk/src/main/jni/src/jni/convert_utils.cc @@ -196,6 +196,7 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, j_env->DeleteLocalRef(method_name_str); j_env->DeleteLocalRef(call_id_str); auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); return std::make_tuple(true, "", true); @@ -210,7 +211,9 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, if (!std::get<0>(to_array_tuple)) { return std::make_tuple(false, std::get<1>(to_array_tuple), false); } - auto ref = std::make_shared(j_env, std::get<2>(to_array_tuple)); + auto j_obj = std::get<2>(to_array_tuple); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); return std::make_tuple(true, "", true); @@ -225,7 +228,9 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, if (!std::get<0>(to_map_tuple)) { return std::make_tuple(false, std::get<1>(to_map_tuple), false); } - auto ref = std::make_shared(j_env, std::get<2>(to_map_tuple)); + auto j_obj = std::get<2>(to_map_tuple); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); return std::make_tuple(true, "", true); @@ -237,8 +242,9 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, if (!ctx->GetValueBoolean(value, &b)) { return std::make_tuple(false, "value must be boolean", false); } - auto ref = std::make_shared(j_env, - j_env->NewObject(boolean_clazz, boolean_constructor, b)); + auto j_obj = j_env->NewObject(boolean_clazz, boolean_constructor, b); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); return std::make_tuple(true, "", true); @@ -253,8 +259,9 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, } else { return std::make_tuple(false, "value must be string", false); } - - auto ref = std::make_shared(j_env, j_env->NewStringUTF(str.c_str())); + auto j_obj = j_env->NewStringUTF(str.c_str()); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); return std::make_tuple(true, "", true); @@ -267,8 +274,10 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, if (!ctx->GetValueNumber(value, &num)) { return std::make_tuple(true, "value must be int", false); } - auto ref = std::make_shared(j_env, j_env->NewObject( - integer_clazz, integer_constructor, num)); + auto j_obj = j_env->NewObject( + integer_clazz, integer_constructor, num); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); } else { @@ -278,13 +287,17 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, } if (type == kDoubleObject) { - auto ref = std::make_shared(j_env, j_env->NewObject( - double_clazz, double_constructor, num)); + auto j_obj = j_env->NewObject( + double_clazz, double_constructor, num); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); } else if (type == kFloatObject) { - auto ref = std::make_shared(j_env, j_env->NewObject( - float_clazz, float_constructor, static_cast(num))); + auto j_obj = j_env->NewObject( + float_clazz, float_constructor, static_cast(num)); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); } else if (type == kLongObject) { @@ -292,8 +305,10 @@ ConvertUtils::HandleObjectType(const std::shared_ptr& ctx, if (!hippy::base::numeric_cast(num, jlong_value)) { return std::make_tuple(true, "value out of jlong boundary", false); } - auto ref = std::make_shared(j_env, j_env->NewObject( - long_clazz, long_constructor, jlong_value)); + auto j_obj = j_env->NewObject( + long_clazz, long_constructor, jlong_value); + auto ref = std::make_shared(j_env, j_obj); + j_env->DeleteLocalRef(j_obj); global_refs.push_back(ref); j_args.l = ref->GetObj(); } else {