Skip to content
Prev 35101 / 63424 Next

:Re: PROTECT and OCaml GC.

It does not have to be a functional language.
To see it in use within a some-language-to-R bridge, you can check the
source in JRI, rpy2.
I can mostly speak for rpy2, and the way it is done there relies on both 
R and Python's GC. Creating a anonymous R object presented to the Python 
world is first "R_preserved" (from garbage collection from R) then using 
Python's reference counting mechanism, calling an "R_Release" whenever 
the Python wrapper is available for garbage collection (in fact there is 
a twist, but this is roughly the way it is working). In your case, 
you'll use the OCaml GC system (and "R_release" the R object when its 
OCaml representation is going for garbage collection).
Rpy2 can do a lot of that, and probably so can JRI.
Symbols are used in various places in R, checking the outcome of 
deparse(substitute()) on an anonymous variable of large size could tell 
you that some things will not work out of the box nicely.


HTH,


L.