Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak when using sorting methods on rtensor? #138

Open
ThibHlln opened this issue May 15, 2023 · 1 comment
Open

memory leak when using sorting methods on rtensor? #138

ThibHlln opened this issue May 15, 2023 · 1 comment

Comments

@ThibHlln
Copy link
Contributor

ThibHlln commented May 15, 2023

Hi,

When I am using xt::sort or xt::quantile on xt::rtensor, there seems to be some form of memory leak.

For example, the following C++ function:

#include <xtensor/xsort.hpp>
#include <xtensor-r/rtensor.hpp>
#include <xtensor-r/rarray.hpp>

#include <Rcpp.h>

// [[Rcpp::plugins(cpp14)]]

// [[Rcpp::export("sort_cpp")]]
xt::rarray<double> sort_cpp(xt::rtensor<double, 4> q)
{
  xt::rarray<double> arr = xt::sort(q, 3);
  return arr;
}

when used repeatedly in R (even with explicit garbage collection), e.g.:

library(myTestLib)

q = array(
  data=rep(c(0.6), 10 * 2 * 11 * 2080),
  dim=c(10, 2, 11, 2080)
)

for (i in 1:1000) 
{
  myTestLib::sort_cpp(q)
  gc()
}

will gradually use more and more memory as one progresses through the loop.

I have put together a small repository to demonstrate the potential memory leak: https://github.com/ThibHlln/myTestLib

Are you able to reproduce my problem? Do you notice a memory leak too?

Thanks.

@ThibHlln
Copy link
Contributor Author

For information, the problem does not occur if rtensor are replaced with rarray.

Also, in a similar context, the problem does not occur either when using pytensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant