[Rcpp-devel] Memory leak when a warning is catched before the end of a function

Dirk Eddelbuettel edd at debian.org
Wed Apr 29 19:36:00 CEST 2026


On 29 April 2026 at 12:25, Dirk Eddelbuettel wrote:
| Well what is your real question here? In R you cannot have a data.frame with
| different column lengths, and Rcpp long documented that it does not recycle.
| 
| C++ still has resource control so the destructor should still be reached. You
| can turn on debug mode / add a 'print' to the destructor.

Also no leak on

   R -d "valgrind --tool=memcheck --leak-check=full --track-origins=yes"  \
        -e "Rcpp::cppFunction('Rcpp::DataFrame test(SEXP a, SEXP b) { \
               Rcpp::DataFrame DF; \
               DF.push_back(a);    \
               DF.push_back(b);    \
              return DF; }');     \
            tryCatch( test(1:4, 11:14), warning = function(w) {} )"

i.e. when I make it a saner DF.

Kevin already identified the warning text created as the issue. Looks like
we're on it.  Thanks for alerting us.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list