diff --git a/ipc/native/src/napi_common/include/napi_remote_object_holder.h b/ipc/native/src/napi_common/include/napi_remote_object_holder.h index 204e5a152cf7c78bd13b46cf21fc064020cd41ce..eb53fba76c83f44317901e9807e64943af0d8839 100644 --- a/ipc/native/src/napi_common/include/napi_remote_object_holder.h +++ b/ipc/native/src/napi_common/include/napi_remote_object_holder.h @@ -27,7 +27,7 @@ namespace OHOS { class NAPIRemoteObjectHolder : public RefBase { public: explicit NAPIRemoteObjectHolder(napi_env env, const std::u16string &descriptor, napi_value thisVar); - ~NAPIRemoteObjectHolder(); + ~NAPIRemoteObjectHolder() = default; sptr Get(); void Set(sptr object); void attachLocalInterface(napi_value localInterface, std::string &descriptor); diff --git a/ipc/native/src/napi_common/source/napi_remote_object_holder.cpp b/ipc/native/src/napi_common/source/napi_remote_object_holder.cpp index 48f447ed83a813775e7afa2b40018b9fa7e5c95c..56a479b61f6363a57f155e0b73cf0c39e832a1f4 100644 --- a/ipc/native/src/napi_common/source/napi_remote_object_holder.cpp +++ b/ipc/native/src/napi_common/source/napi_remote_object_holder.cpp @@ -38,14 +38,6 @@ NAPIRemoteObjectHolder::NAPIRemoteObjectHolder(napi_env env, const std::u16strin napi_create_reference(env, thisVar, 0, &jsObjectRef_); } -NAPIRemoteObjectHolder::~NAPIRemoteObjectHolder() -{ - // free the reference of object. - if (localInterfaceRef_ != nullptr && env_ != nullptr) { - napi_delete_reference(env_, localInterfaceRef_); - } -} - sptr NAPIRemoteObjectHolder::Get() { std::lock_guard lockGuard(mutex_); @@ -102,10 +94,7 @@ void NAPIRemoteObjectHolder::attachLocalInterface(napi_value localInterface, std ZLOGE(LOG_LABEL, "Js env has been destructed"); return; } - if (localInterfaceRef_ != nullptr) { - napi_delete_reference(env_, localInterfaceRef_); - } - napi_create_reference(env_, localInterface, 1, &localInterfaceRef_); + napi_create_reference(env_, localInterface, 0, &localInterfaceRef_); descriptor_ = Str8ToStr16(descriptor); }