[Rd] Destructive str(...)?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Oct 31 11:01:30 CET 2004


Simon Urbanek <simon.urbanek at math.uni-augsburg.de> writes:

> Now, hold on a second - I thought the main point of EXTPTR is that the
> finalizer is called only once, that is when the last instance of the
> reference is disposed of by the gc (no matter how many copies existed
> meanwhile). Am I wrong and/or did I miss something? I did some tests
> which support my view, but one never knows ...

How do you ensure that the finalizer is called once? By *not* copying
the reference object! You can have as many references to it as you
like (i.e. assign it to multiple variables), and the object itself is
not removed until the last reference is gone, but if you modify the
object (most likely by setting attributes, but you might also change
the C pointer payload in a C routine), all "copies" are changed:

> x <- as.tclObj(pi)
> x
<Tcl> 3.14159265359
> y <- x
> y
<Tcl> 3.14159265359
> mode(x)
[1] "externalptr"
> attr(x, "Simon") <- "Urbanek"
> attributes(y)
$class
[1] "tclObj"

$Simon
[1] "Urbanek"



-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list