Browse Source

fix(mge/tensor): fix mem leak when getting value in trace

GitOrigin-RevId: 1dabd88e09
release-1.2
Megvii Engine Team 4 years ago
parent
commit
e0fffa5286
2 changed files with 4 additions and 3 deletions
  1. +1
    -2
      imperative/python/megengine/jit/tracing.py
  2. +3
    -1
      imperative/python/src/tensor.cpp

+ 1
- 2
imperative/python/megengine/jit/tracing.py View File

@@ -1002,8 +1002,7 @@ class CompiledTensorProxy:
else: else:
# c++ will throw TraceReadError # c++ will throw TraceReadError
return None return None
if self._isscalar:
self.__value = self.__value.squeeze()
# c++ side will handle scalar case
return self.__value return self.__value


def _dev_tensor(self): def _dev_tensor(self):


+ 3
- 1
imperative/python/src/tensor.cpp View File

@@ -393,7 +393,9 @@ PyObject* TensorWrapper::numpy() {
throw TraceReadError("value of this tensor is not read in trace"); throw TraceReadError("value of this tensor is not read in trace");
} }
if (m_tensor->m_flags & Tensor::Flags::SCALAR) { if (m_tensor->m_flags & Tensor::Flags::SCALAR) {
np_val = PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(np_val));
PyObject *np_scalar = PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(np_val));
Py_DECREF(np_val);
return np_scalar;
} }
return np_val; return np_val;
} }


Loading…
Cancel
Save