简体   繁体   中英

Having Trouble Debugging Possible Rcpp Memory Leak

I am writing an R package using RcppEigen called RcppCoDA

I think there may be a memory leak somewhere in my project but I am not sure. I am unfortunately having trouble running Valgrind as it seems it may not support the OS X Mojave and I am running into errors detailed here .

I think it should be pretty easy to reproduce the error:

library(RcppCoDA) # devtools::install_github("jsilve24/RcppCoDA")
library(microbenchmark)

d <- c(100,1000)
X <- matrix(abs(rnorm(prod(d))), d[1], d[2])
X <- clo(X)

# This runs fine
z <- RcppCoDA::alr(X, d=4)

# This for some reason takes forever to run... I think this might be a bug
for (i in 1:1000){
  z <- RcppCoDA::alr(X, d=4)  
}


# This causes RStudio to crash... or takes forever to run...
microbenchmark(
  RcppCoDA::alr(X, d=4), times=10
)

I have reread the code over and over and don't see how I could be having memory errors unless I am just misusing Rcpp somehow... Unfortunately, as I can't seem to get Valgrind to work as outlined here I am really at a loss for how to debug. I am not even sure if there is a bug in my code or somewhere else.

Any help would be most appreciated!

Thanks to some helpful comments I was able to get Valgrind working in a docker image.

Just an outline of how I did it:

  1. I used the docker image: rocker/rstudio
  2. Start-up the image/container: docker run rocker/rstudio
  3. With that running: In a separate terminal: docker ps
  4. Grab the container ID of the running image and then run: docker exec -it <containerID> bash
  5. Install valgrind and a number of other things required by devtools
  6. Run R with valgrind debug: R -d "valgrind --leak-check=full"
  7. Run whatever code is causing errors and evaluate valgrind output.

Thank you for the help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM