Jan van der Laan
2018-Aug-07 13:19 UTC
[Rd] Run garbage collector when too many open files
In my package [1] I open handles to temporary files from c++, pointer to the objects containing those handles are returned to R as external pointer objects. The files are deleted when 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, for example, that another package of mine using this package generates an error when its tests are run [2]. 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 [1] https://cran.r-project.org/web/packages/lvec/index.html [2] https://cran.r-project.org/web/checks/check_results_reclin.html
Apparently Analagous Threads
- [R-pkg-devel] Run garbage collector when too many open files
- Run garbage collector when too many open files
- [R-pkg-devel] Run garbage collector when too many open files
- [LLVMdev] open source multithreaded garbage collector suitable for LLVM applications?
- [LLVMdev] A working garbage collector - finally :)