2

R (3.3.2, Windows 7) crashes after about 1000 iterations of dyn.load() being used in a for loop. This does not happen in Ubuntu. This behaviour is observed for dll files created from Rcpp and TMB code, but I don't think it is related to either of these packages. The crash message is:

Problem Event Name: APPCRASH
Application Name:   rsession.exe
Application Version:    1.0.136.0
Application Timestamp:  583f5668
Fault Module Name:  testRcppRepeatDynLoad.dll

The following is a mimimal reproducible example on my computer:

First, create an Rcpp package called testRcppRepeatDynLoad (in Rstudio, create package in new directory, select 'create package with Rcpp'.). Building the package with CTRL-SHIFT-B creates a dll file in the src folder, which we will load using dyn.load.

This code crashes the R session after 1050 iterations:

while (i < 2000) {
    i = i + 1
    print(i)
    dyn.load('src/testRcppRepeatDynLoad.dll')
    dyn.unload('src/testRcppRepeatDynLoad.dll')

}

The same thing happens for a dll file created by TMB::compile.

Alex
  • 15,186
  • 15
  • 73
  • 127
  • "Doctor doctor it hurts when I do that.". "Then don't do it". – Dirk Eddelbuettel Nov 28 '17 at 12:24
  • 1
    There is no question here. If we do not know what is in that DLL, and why on Mother Earth you think you would need to load and unload repeated (not something _Writing R Extensions_ suggests you should assume to be capable of) then there is nothing we can do. See [how to create a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example-aka-mcve-minimal-complete-and-ver). – Dirk Eddelbuettel Nov 28 '17 at 12:26
  • Some possibly relevant info in this [QA](https://stackoverflow.com/questions/26691878/must-r-packages-unload-dynamic-libraries-when-they-unload) – BrodieG Nov 28 '17 at 14:32
  • Hi Dirk, sorry if the op wasn't clear, but the dll is whatever results from building the package made using `Rcpp.package.skeleton`. That is what the rstudio option create new package with rcpp does. https://support.rstudio.com/hc/en-us/articles/200486088-Using-Rcpp-with-RStudio?mobile_site=true – Alex Nov 28 '17 at 19:46
  • Ok. Then show me where Writing R Extensions, or any other R manual, suggests you can load and unload 2k times. Some of us are debating whether you can even cleanly unload _once_. – Dirk Eddelbuettel Nov 28 '17 at 21:40
  • Also show where the Rcpp suggests you should manually call `dyn.load()`. – Dirk Eddelbuettel Nov 28 '17 at 21:41
  • Dirk, I read the link that @BrodieG pointed out and am starting to understand that there may be an issue with the unload process. As for your questions regarding `Rcpp`, I hope I have been clear in the OP that I do not think that this issue is related to `Rcpp` or `TMB`. For the purposes of making a reproducible example (i.e. build a `dll`), I assumed that more people will be able to build a `Rcpp` package dll rather than a `TMB` one. I will edit the question to include the `TMB` example since your comments seem to suggest that I should not use a `Rcpp` package dll to test `dyn.load`... – Alex Nov 28 '17 at 23:06

0 Answers0