[Rd] [R] R garbage collection

Luke Tierney luke at stat.uiowa.edu
Fri Mar 31 17:29:24 CEST 2006


The allocations described as User-Controlled are not part of the
GC-managed heap.  The ones described as Transient happen to be but
that is not user visible; alternate implementations might insure that
they are freed as soon as the appropriate context is left.

If you are interested in managing the lifetime of heap-allocated
objects then you register roots for the GC with R_PreserveObject.

luke

On Fri, 31 Mar 2006, Prof Brian Ripley wrote:

> On Thu, 30 Mar 2006, Jeff Henrikson wrote:
>
>> r-help,
>
> [Moved to R-devel.]
>
>> The R manual lists two types of memory: transient and user-controlled.
>> If I have transient blocks reachable from the globals only by traversal
>> through user-controlled blocks, will they be correctly preserved?
>
> I don't understand your terminology, especially 'traversal'.  It is not
> normal to have either type of block reachable through R objects, and if
> you are using something like external pointers, the answer would be no.
>
>> Secondly, what are the ways to mark user controlled blocks as "roots"
>> for the garbage collector, so that transient blocks they reference stay
>> uncollected?  So far I can only deduce that as long as the answer to my
>> first question is yes, I can bind an arbitrary symbol to them in the
>> global environment.  Is this the best way?
>
> I think you are referring to blocks allocated by R_alloc.  The manual says
>
>   This memory is taken from the heap, and released at the end of the .C,
>   .Call or .External call. Users can also manage it, by noting the current
>   position with a call to vmaxget and clearing memory allocated
>   subsequently by a call to vmaxset. This is only recommended for experts.
>
> If you want to allocate storage as part of an R object, this is not the
> best way to do it (allocVector etc are).  It is a side-effect of the
> current implementation that memory allocated by R_alloc which is made part
> of an object will be protected for the lifetime of that object, but this
> is not documented and should not be relied on.  (I am thinking if for
> example a block is made into a CHARSXP 'by hand', but the documented route
> is mkChar which makes a copy.)
>
>> Jeff Henrikson
>>
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> Please do, including the question `which list': this clearly belongs on
> R-devel.
>
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list