-
-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
Description
This code shows that CHARSXP
s can be garbage collected:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector test() {
Function gc("gc");
SEXP character = Rf_mkChar("ouch");
SEXP string = Rf_mkString("ouch");
Shield<SEXP> other(Rf_allocVector(INTSXP, 1E6));
gc();
Rprintf("CHARSXP:\n");
Rf_PrintValue(character);
Rprintf("STRSXP:\n");
Rf_PrintValue(string);
return wrap(other);
}
/*** R
gctorture(TRUE)
invisible(test())
gctorture(FALSE)
*/
> Rcpp::sourceCpp('~/scratch/ouch.cpp')
> gctorture(TRUE)
> invisible(test())
CHARSXP:
[1] FALSE
STRSXP:
<garbage>
> gctorture(FALSE)
The CHARSXP
has been replaced with garbage, as it has been GCed.
Metadata
Metadata
Assignees
Labels
No labels