Coder Social home page Coder Social logo

Comments (5)

dmbates avatar dmbates commented on June 10, 2024

Not quite 'always'. The R garbage collector is currently a generational mark/sweep design that examines the 'named' field in the sxpinfo 32-bit word at the beginning of an SEXPREC. A value of 0 means that the object is not assigned to a name and is available for garbage collection unless it can be reached from another object. I'm not clear on the distinction between values of 1 and 2 in that field.

The conservative approach is to call PreserveObject on every value from rawvector or to copy the values into Julia objects. Copying would mean that you couldn't modify the object's value as seen by R, which you may want to do. Also, it can result in unnecessary storage allocation. Calling PreserveObject on the value results in its not being available for garbage collection in R and could mean excessive storage allocation. If PreserveObject were to be called then the Julia object should have a finalizer that calles ReleaseObject.

Perhaps it would be best to have a discussion on the julia-stats list regarding the best strategy. I'll start a thread.

from rcall.jl.

randy3k avatar randy3k commented on June 10, 2024

Don't we always need to protect a R object from GC when we expose it to julia? My example in #6 clear shows that it is necessary.

I understand that PreserveObject and ReleaseObject should be using as a pair. And that is precisely what Rif.jl and RCalling.jl are actually doing.

It may not be desirable to call PreserveObject on every element of rawvector of a long vector.
From my experience in RCalling.jl, if the number of preserved objects is large, say 100,000. The time to execute the finalizers can takes up to 30 secs, which is of course not acceptable.

It would be beneficial to have a discussion on the julia-stats list.

from rcall.jl.

dmbates avatar dmbates commented on June 10, 2024

There can cases where an R object does not need protection, if, for example, you are going to copy it into a Julia object immediately. If you just want an R dataset you could retrieve it in R and immediately copy the contents to Julia vectors. Evaluating a symbol in R returns an object that, by definition, has a named field of 2, and hence will not be garbage collected.

from rcall.jl.

dmbates avatar dmbates commented on June 10, 2024

See the julia-stats thread

from rcall.jl.

dmbates avatar dmbates commented on June 10, 2024

6f529c2

from rcall.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.