This project is read-only.

REngine Not Getting Disposed when Called from Web UI, Web Service or WCF Service

Nov 10, 2014 at 6:57 PM
Edited Nov 10, 2014 at 6:58 PM
I am putting my interaction with the REngine (and R.NET) behind a WCF Service. It was previously working ok, but as soon as I implemented IDisposable in the Adapter (that calls R.NET) that's called by my WCF Service, I am getting an error on 2nd call where it's timing out on the following method:

GetFunction<setup_Rmainloop>()();

Or it's showing that the engine is already disposed when it checks for that in the engine initialization.

I dispose of the engine after it's been used and each time coming into the service I check to see if the engine needs to be created and initialized or not. Calling from a Console or windows application does not have this issue. So I guess calling from a Web-based application, something is keeping the engine from being completely disposed or cached and this is causing the issue?

If I remove the call to the Dispose() method in my Adapter, which is called by a WCF service then it runs fine. So, should I not dispose of the engine when being used from a web-based application? Just wondering if anyone else was having issues with disposing of the engine in a web environment.

thanks.
Nov 12, 2014 at 1:08 AM
There's no reason to dispose of the engine. R is an unmanaged application written in C. Disposing is a managed .Net concept and has no effect on unmanaged dlls, like R and its subordinate dlls. Calling Dispose on the REngine is good form, but it won't allow you to get a new instance of the REngine, which is why the dispose check is there in the first place.


I'm not certain what criteria you are using when you say it works from a console or Windows application as this behavior is part of interop and unmanaged application under .Net. Using WCF as an IPC mechanism for hosting R and R.Net will not change things.