xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
345 stars 58 forks source link

Memory leak with std::tuple<xt::pytensor<...>> #156

Closed daniel-ziegler closed 6 years ago

daniel-ziegler commented 6 years ago

Putting an xt::pytensor inside an std::tuple seems to cause a memory leak, e.g.:

void leak() {
    xt::pytensor<float, 1> ones = xt::ones<float>({10});
    std::tuple<xt::pytensor<float, 1>> tup(ones);
}

Using pybind11's py::tuple doesn't cause the same problem.

Am I doing something wrong here or is this a bug?

See https://github.com/daniel-ziegler/tuple_leak/blob/master/tuple_fun.cpp for a full demonstration of the problem; you can install the package and run https://github.com/daniel-ziegler/tuple_leak/blob/master/demo.py. Intriguingly, it looks like the size of the array doesn't affect how much memory gets leaked.

I'm on pybind11 version 2.2.3 and xtensor-python version 0.19.0.

wolfv commented 6 years ago

Thanks for the report! I'll look into that!

wolfv commented 6 years ago

Ok, thanks for your package -- I was able to reproduce this behavior.