[C++ API] Added reference counting to ObjectRef (#13058)

* Added reference counting to ObjectRef

* Addressed the comments
This commit is contained in:
Alind Khare authored and GitHub committed 2020-12-24 09:32:52 -08:00
1 parent 4bcd475671
commit 2059a2090d
2 files changed
+32 -26

No files matched your search

+12
View File
@@ -16,6 +16,7 @@ template <typename T>
class ObjectRef {
public:
ObjectRef();
~ObjectRef();
ObjectRef(const ObjectID &id);
@@ -46,6 +47,17 @@ ObjectRef<T>::ObjectRef() {}
template <typename T>
ObjectRef<T>::ObjectRef(const ObjectID &id) {
id_ = id;
if (CoreWorkerProcess::IsInitialized()) {
auto &core_worker = CoreWorkerProcess::GetCoreWorker();
core_worker.AddLocalReference(id_);
}
}
template <typename T>
ObjectRef<T>::~ObjectRef() {
if (CoreWorkerProcess::IsInitialized()) {
auto &core_worker = CoreWorkerProcess::GetCoreWorker();
core_worker.RemoveLocalReference(id_);
}
}
template <typename T>