[Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

Dirk Eddelbuettel edd at debian.org
Tue Feb 12 04:22:33 CET 2013


On 11 February 2013 at 19:10, Yan Zhou wrote:
| It seems to me that XPtr is like an ownership pointer. It is much like
| unique_ptr. What you need here is a non-owning reference pointer, like
| weak_ptr.
| 
| Have you tried
| 
| XPtr<A> A::getPtr(){
|    return(XPtr<A>(this, false));
| }
| 
| With the optional argument, a finalizer is not set and the gc will not delete
| the C++ object. I haven't used XPtr in this way, but from the document I guess
| this shall work.

Nice work. Should have thought of the finalizer -- on quick testing this does
indeed do the trick. Well done.

Dirk

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


More information about the Rcpp-devel mailing list