Skip to content

Documentaion about when we free memory  #311

@kngwyu

Description

@kngwyu

I got an issue in rust-numpy repo today.
See the below code:

fn main() {
    let v = vec![0; 100_000];
    let gil = Python::acquire_gil();
    let py = gil.python();
    loop {
        let py_arr = PyArray2::from_vec2(py, &vec![v.clone()]).unwrap();
        ();
        // &PyArray2 drops and nothing happens
    }
    // GILGruard drops and Python objects are freed
}

In such a case, I think most users assume that py_arr is freed when an iteration of the loop ends, but truly, it's freed after GILGuard drops.

So my suggestions are:

  • We should have a document that clearly demonstrates objects are freed after GILGuard drops
  • How about adding a 'freed-after-drop' object wrapper? But I'm not sure we can do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions