taichi icon indicating copy to clipboard operation
taichi copied to clipboard

Ndarray lifetime management

Open ailzhang opened this issue 2 years ago • 0 comments

Current ndarray implementation doesn't respect python. For example if you do del ndarray1 only the ndarray object is deleted but the underlying memory is not freed. (managed by Program)

Ideally we'd want ndarray memory to be freed either when python GCs it or C++ Program gets destructed, whichever comes first.

  • Ndarray cannot be managed solely by Python (like holding a shared pointer to the Device). Otherwise ti.reset() won't be able to destruct Device object as it does before.
  • Ndarray cannot be solely managed by C++ Program class. Otherwise the underlying memory of ndarray won't be freed even after user calls del ndarray.

We gave this a try but had to revert it in https://github.com/taichi-dev/taichi/pull/5019. Need to understand the root cause of the bug first.

ailzhang avatar May 25 '22 08:05 ailzhang