Skip to content

Commit 49b23fd

Browse files
author
Bernardo Covas
committed
[lang] free ndarray memory on the base class
classes inheriting from Ndarray should have their memory released
1 parent ba0e81d commit 49b23fd

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

python/taichi/lang/_ndarray.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ def __getitem__(self, key):
6060
"""
6161
raise NotImplementedError()
6262

63+
def __del__(self):
64+
rt = impl.get_runtime()
65+
if (
66+
self.arr is not None and
67+
impl is not None and
68+
rt is not None and
69+
rt.prog is not None
70+
):
71+
impl.get_runtime().prog.delete_ndarray(self.arr)
72+
6373
@python_scope
6474
def fill(self, val):
6575
"""Fills ndarray with a specific scalar value.
@@ -243,9 +253,6 @@ def __init__(self, dtype, arr_shape):
243253
self.shape = tuple(self.arr.shape)
244254
self.element_type = dtype
245255

246-
def __del__(self):
247-
if impl is not None and impl.get_runtime() is not None and impl.get_runtime().prog is not None:
248-
impl.get_runtime().prog.delete_ndarray(self.arr)
249256

250257
@property
251258
def element_shape(self):

0 commit comments

Comments
 (0)