[R-pkg-devel] Run garbage collector when too many open files

Uwe Ligges ligge@ @ending from @t@ti@tik@tu-dortmund@de
Tue Aug 7 15:24:37 CEST 2018


Why not add functionality that allows to delete object + runs cleanup code?

Best,
Uwe Ligges



On 07.08.2018 14:26, Jan van der Laan wrote:
> 
> 
> In my package I open handles to temporary files from c++, handles to 
> them are returned to R through vptr objects. The files are deleted then 
> the corresponding R-object is deleted and the garbage collector runs:
> 
> a <- lvec(10, "integer")
> rm(a)
> 
> Then when the garbage collector runs the file is deleted. However, on 
> some platforms (probably with lower limits on the maximum number of file 
> handles a process can have open), I run into the problem that the 
> garbage collector doesn't run often enough. In this case that means that 
> another package of mine using this package generates an error when its 
> tests are run.
> 
> The simplest solution is to add some calls to gc() in my tests. But a 
> more general/automatic solution would be nice.
> 
> I thought about something in the lines of
> 
> robust_lvec <- function(...) {
>    tryCatch({
>      lvec(...)
>    }, error = function(e) {
>      gc()
>      lvec(...) # duplicated code
>    })
> }
> 
> e.g. try to open a file, when that fails call the garbage collector and 
> try again. However, this introduces duplicated code (in this case only 
> one line, but that can be more), and doesn't help if it is another 
> function that tries to open a file.
> 
> Is there a better solution?
> 
> Thanks!
> 
> Jan
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list