[Rd] destructor for S4 class objects in analogy to C++

Simon Urbanek simon.urbanek at r-project.org
Tue Jul 21 19:26:36 CEST 2009


David,

On Jul 21, 2009, at 13:00 , David Scherrer wrote:

> I'm wondering if there is a way to define a destructor function (to  
> free memory) for S4 class objects in analogy to C++?

The analogy doesn't work, because in C++ you have pass-by-reference  
semantics, but in R you have pass-by-value. Hence in R there is no  
"one" object that you could finalize - there may be dozens of copies  
of your S4 object, so which one would you finalize? However, you can  
register a finalizer for reference-semantics objects (if that's what  
you really have), see ?reg.finalizer (and on C level  
R_Register*Finalizer* functions).

Cheers,
Simon


> rm() combined with gc() does not seem to be a good idea (Chambers,  
> 2008).
> So could it be done on the C/C++ level or is it even already  
> available in
> the "internals"?
>
> Many thanks,
> David
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



More information about the R-devel mailing list