Skip to content
Prev 9164 / 10988 Next

[Rcpp-devel] freeing memory

I have used the example rinside_sample1.cpp as a basis for a short 
routine to transmit data from C++ to R and to recover the results from R 
to C++. On the face of it, everything works nicely both in our mainframe 
(linux) computer at ?AU and on the supercomputers at CSC IT Center of 
Science (Helsinki). Before proceeding - not being an R expert myself - I 
wanted to check the memory absorbance of the system. When checking the 
program flow with Valgrind, the debugger signals that several blocks of 
data are still reachable when exiting. This cannot be,
since multiple calls to the routine would quickly absorb the CPU.

So, how do I free memory for example when allocating it through commands
such as:
   Rcpp::NumericMatrix C_R=createMatrix(CATSM_INFO[0],cm,cn);
   Rcpp::NumericVector v = R.parseEval(str);
   string result(argv[1]);

How should the example rinside_sample1.cpp be modified to get this 
straight and to avoid the risk of excessive memory absorbance in 
multiple calls?