[Rcpp-devel] reference counting, garbage collection, etc ....

Dirk Eddelbuettel edd at debian.org
Sat Jan 2 15:07:53 CET 2010

On 2 January 2010 at 13:37, Romain François wrote:
| Right, so looking at R_PreserveObject and R_ReleaseObject (still waiting 
| for some insight from R-devel) it seems that we can preserve and release 
| the same SEXP more than once. preserve adds the sexp to the list of 
| preserved SEXP (even if it is there already), and release release the 
| first one it finds.
| This leads me to thinking that we should make the garbage collection 
| stuff automatic and hidden, i.e when setting the SEXP of an RObject, we 
| automatically preserve it, and we release it automatically when the 
| object goes out of scope.

That was always the idea with Rcpp objects.  The classes manage memory, the
user doesn't have to worry.

And the design was always like this -- release memory in the dtor.
| Currently we have to manage this business manually, which will leads to 
| problems.

"We" as in class implementers/authors, or "we" as users?   As authors, yes we
do have to manage this, but that is because R forces us to, no?

| So i propose that RObject::m_sexp becomes private (as opposed to 
| protected) and we had a protected setSEXP that :
| - release the current SEXP if there is one
| - preserve the new SEXP
| and make preserve and release protected (maybe even private members of 
| RObject), and remove the preserved bool.

Sounds like a technically more sounds implementation, but nothing really
changes for the user, no?  Ie there never was a user-accessibly method to 

Am I missing something?   


Three out of two people have difficulties with fractions.

More information about the Rcpp-devel mailing list