This project is read-only.

Entry point was not found exception

Mar 27, 2014 at 1:59 AM

I'm getting EntryPointNotFoundException for the function R_ReleaseObject.
I'm using R version 2.15.3 and probably this method is not implemented there.

Is it possible to configure R.Net to be aware of the underlying R version?
Mar 27, 2014 at 2:07 AM
Noted; I'll look at it in the coming days if I can (got to deal with pressing deadlines).

If you are on Windows, I'd recommend you have a look at CFF Explorer suite to see what functions R.dll exports.
Mar 27, 2014 at 2:48 AM
The function is exposed from R.dll and I actually see it being resolved successfully multiple times.
I think it might be a race condition, where the handle is being closed before all objects are being released, leading to GetProcAddress to fail and return null.

I see that when this issue occurs, it is happening during a finalizer call.
So probably what happened is that the engine handle was disposed (either in a different finalizer or by explicitly calling Dispose) and then a GC kicked in and started finalizing other objects. At this point, they failed.

It seems like either:
  1. Some references are not being kept, so the GC releases the engine before other objects.
  2. Maybe some objects should be IDisposable and they should be disposed earlier (and not wait for the finalizaer).
Quick question about GetFunction. Wouldn't it be a good idea to cache all resolved functions in a dictionary, instead of PInvoking multiple times per function?
Mar 27, 2014 at 2:55 AM
I think I found the issue.

I'm setting attributes on some vectors.
To do that I create a character vector to hold the attribute value.
This vector is never disposed, so at the final GC, its finalizer is called, probably after the engine handle is closed.

What should be the pattern of disposing vectors?
Can I dispose my vector immediately after setting the attribute value, or will this action lead to some memory being released and then R will have a reference to a dangling pointer for this attribute?
Does R copy the attribute content or does it use the memory allocated by my call?
Mar 27, 2014 at 10:30 AM
Found more info on this issue.
There are a lot of places in the code where a safe handle object is created and not disposed.
All the calls to GetPredefinedSymbol leave a safe handle object (SymbolicExpression) behind.
Also, InternalString is created without being disposed and InternalString.GetInternalValue is called without disposing.
Probably there are more.
All these leave behind undisposed objects, and then, if the app domain is unloaded, sometimes the engine finalizer is called before these objects' finalizers leading to this error.

So now simple operations like getting an entry from a CharacterVector leave behind several undisposed objects.

This brings the question why GetPredefinedSymbol is called again and again for the same values instead of caching the results.
Mar 27, 2014 at 9:29 PM
This sounds like issues that have been dealt with on the development branch 'jperraud'; certainly the leakages with character vectors. You may want to work from that branch; it looks like you have no problem starting from source code.

I know there is a now pressing need for an updated release, but I have to go through enough testing. Also, some steps of the release I cannot perform myself.