diff --git a/python/taichi/lang/_ndarray.py b/python/taichi/lang/_ndarray.py index 796366adf345e..ed6fee7b863b7 100644 --- a/python/taichi/lang/_ndarray.py +++ b/python/taichi/lang/_ndarray.py @@ -60,6 +60,14 @@ def __getitem__(self, key): """ raise NotImplementedError() + def __del__(self): + if impl is None or self.arr is None: + return + + rt = impl.get_runtime() + if rt is not None and rt.prog is not None: + rt.prog.delete_ndarray(self.arr) + @python_scope def fill(self, val): """Fills ndarray with a specific scalar value. @@ -243,10 +251,6 @@ def __init__(self, dtype, arr_shape): self.shape = tuple(self.arr.shape) self.element_type = dtype - def __del__(self): - if impl is not None and impl.get_runtime() is not None and impl.get_runtime().prog is not None: - impl.get_runtime().prog.delete_ndarray(self.arr) - @property def element_shape(self): return ()