Skip to content

[Rust] Memory leak in NDArray #6559

Description

@12101111

See https://discuss.tvm.apache.org/t/memory-and-vram-leak-using-rust-frontend/7990

I have found that All NDArray created in rust is NDArray::Borrowed, so they are never freed.

pub enum NDArray {
    Borrowed { handle: ffi::TVMArrayHandle },
    Owned { handle: *mut c_void },
}

impl Drop for NDArray {
    fn drop(&mut self) {
        if let &mut NDArray::Owned { .. } = self {
            check_call!(ffi::TVMArrayFree(self.as_raw_dltensor()));
        }
    }
}

If I remove the check, the memory and vram leak won't happend.

impl Drop for NDArray {
    fn drop(&mut self) {
        check_call!(ffi::TVMArrayFree(self.as_raw_dltensor()));
    }
}

cc @ehsanmok

Metadata

Metadata

Assignees

No one assigned

    Labels

    rustRelated to TVM's Rust bindings

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions