Skip to content
Prev 9475 / 63421 Next

R-1.7.0: Rproxy.dll loadlibrary/freelibrary error (PR#2914)

Just had a look at the code (but no further analysis at the moment).

What you're trying to do is you load and unload the library some times.
This is something you normally shouldn't do ;-)

1. Windows has some problems in releasing all memory of a DLL. Just
   loading and unloading a DLL (just containing text resources, no code
   at all) causes a memory leak (and a significant delay in time)
2. R itself assumes (or that's what I think) that all resources which are
   not explicitly freed are released by the operating system when R quits

Of course, you're right, that this could be a problem (the current implemen-
tation of the COM server loads the DLL in Init() and unloads in Terminate()).
But on the other hand, the COM server also gets terminated after the reference
to the COM object is released and every client gets a new server process.

If R 1.6.2 doesn't behave the same as you stated, there may be some newly
allocated resources which don't get freed (maybe statics which you can only
handle safely in an atexit() routine).

The question to Duncan now is if you are aware of any resources which can/should
be freed by rproxy.dll or by R. Anything we can do about it.

Venkatesh: Maybe you can just keep a single reference to the proxy object
so you won't hit the problem. Or use the COM server, which will automatically
handle this for you (out of process).

Best,
Thomas