diff --git a/paddle/fluid/pybind/eager.cc b/paddle/fluid/pybind/eager.cc index 2903d6663b8aa..96e78cafec007 100644 --- a/paddle/fluid/pybind/eager.cc +++ b/paddle/fluid/pybind/eager.cc @@ -45,7 +45,7 @@ PyObject* eagertensor_new(PyTypeObject* type, PyObject* args, } static void eagertensor_dealloc(EagerTensorObject* self) { - // TODO(wanghuancoder): Call destructor here. + self->eagertensor.~EagerTensor(); Py_TYPE(self)->tp_free(reinterpret_cast(self)); } diff --git a/paddle/fluid/pybind/eager_utils.cc b/paddle/fluid/pybind/eager_utils.cc index 6fb50ff51dfa0..a9756597ff7c3 100644 --- a/paddle/fluid/pybind/eager_utils.cc +++ b/paddle/fluid/pybind/eager_utils.cc @@ -157,6 +157,7 @@ PyObject* ToPyObject(const egr::EagerTensor& value) { PyObject* obj = pEagerTensorType->tp_alloc(pEagerTensorType, 0); if (obj) { auto v = reinterpret_cast(obj); + new (&(v->eagertensor)) egr::EagerTensor(); v->eagertensor = value; } else { PADDLE_THROW(platform::errors::Fatal( @@ -222,6 +223,7 @@ PyObject* ToPyObject(const std::vector& value) { PyObject* obj = pEagerTensorType->tp_alloc(pEagerTensorType, 0); if (obj) { auto v = reinterpret_cast(obj); + new (&(v->eagertensor)) egr::EagerTensor(); v->eagertensor = value[i]; } else { PADDLE_THROW(platform::errors::Fatal(