3

Does anyone know how to use Valgrind to memory debug RInside programs?

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
ggg
  • 1,857
  • 2
  • 21
  • 33

1 Answers1

4

When you use RInside, you create a standalone C++ program---which happens to be linked with R such that R gets embedded.

The use of valgrind is therefore no different then with another C++ program. All code that you want valgrind to analyse may have to rebuilt with the proper setup (see preparing your program at the Valgrind site) and that includes R and RInside if you want Valgrind output on these components too.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Compiling a simple program: `#include int main(){ RInside R; }` with `g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/include -pipe -O0 -g -Wall testv.cpp -L/usr/lib64/R/lib -lR -lblas -llapack -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o testv` i got this [link](http://pastebin.com/xVazvqaF) There were errors! – ggg Oct 30 '11 at 01:23
  • 1
    Thanks for posting that. I am not a great Valgrind user, but that looks *clean* to me: it reports some issues stemming from libz (which R links to) but nothing in R (or RInside) itself. So no issue. To **really** prove that point you could actually add an explicit on purpose leak (ie assign ten times 100k of memory in a loop and never free it) and you should see Valgrind putting the finger on that error. – Dirk Eddelbuettel Oct 30 '11 at 16:03
  • Is it possible to suppress issues originating from libz and other codes, since an RInside user would probably ignore them? – ggg Nov 21 '11 at 06:41