Skip to content

NDArray memory is only released for ScalarNdarray, not any subclass of Ndarray #8763

@BernardoCovas

Description

@BernardoCovas

Describe the bug

ScalarNdarray implements __del__() to allow python to get rid of the allocated memory,
but other subclasses of Ndarray (like VectorNdarray() or MatrixNdarray()) don't implement the same behaviour.
Seems to me the __del__() method should be moved to the Ndarray class.
I tested this simple change and indeed it fixes the memory leak.

To Reproduce

import taichi as ti
import taichi.types as tt

ti.init(ti.gpu)

while True:
    arr = ti.ndarray(tt.vector(3, ti.f32), (1000, 1000))
    arr = arr.to_numpy()
    # whatch gpu memory skyrocket

If, instead:

import taichi as ti
import taichi.types as tt

ti.init(ti.gpu)

while True:
    arr = ti.ndarray(ti.f32, (1000, 1000, 3))
    arr = arr.to_numpy()
    # whatch gpu memory basically stay the same

Log/Screenshots

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions