Bug - Stopping Garbage Collection for an unmanaged Delegate

Jun 26, 2011 at 8:33 PM

Howdy,

I've been using R.NET but hit a problem with it. Specifically, I keep getting the following error:

"A callback was made on a garbage collected delegate of type 'R.NET!RDotNet.Internals.blah3::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called."

After much testing and attempts to fix it, I posted a question about it over on stackoverflow. Here's the link:

http://stackoverflow.com/questions/6485226/stopping-garbage-collection-for-an-unmanaged-delegate/

As you can see, the final suggestion seems to be that the error is due to a bug in R.NET. Is there any way to get around this or fix it?

Thanks! I have to say R.NET has been a brilliant tool so far, and I'm really keen to keep using it.

Jun 27, 2011 at 10:57 AM

I ran into the exact same problem as well when I try to call engine.EagerEvaluate() in the elapsed event of a System.Timer.  Hopefully there will be a fix or an explanation soon!

Coordinator
Jun 27, 2011 at 11:15 AM

This problem can have been solved (reported in  workitem 10) but not published yet as a binary. Please try the newest source code.

Jun 27, 2011 at 10:49 PM

Brilliant, many thanks for your swift reply - I did check through the issue tracker list but managed to miss that one, like a fool! I've tested it out and it now works marvellously :) I'll update my post on SO with this new, correct information.

Aug 17, 2011 at 12:07 AM

Unfortunately this didn't work for me , I seems not stable sometimes it loads normally sometimes not. I am executing the "read.table" instruction. It is craching all the time. I am using it in an MVVM patern as my data source, I don't if it is the reason or not, because I am not calling frequently.

I've tried with the last build till this day, but no way.

Oct 27, 2011 at 5:34 PM

@kos59125: I just ran into this problem as well. I really like RdotNET a lot, it's been a great package. I just ran into this error message last night on code that's been working fine for weeks. I came in this morning, ran the code and it worked perfectly. However, when I ran it again, the same error occurred, and has been giving me problems since. 

I found this discussion thread, and I tried downloading the source files from Jul 12 and the source files from Aug 15. Unfortunately, neither solution could help my code. I hope that a solution comes around soon, would love to get back to using RdotNET again!

In my code, the problem occurs during simple passes to R:

engine.EagerEvaluate("x <- read.csv(\"myTable.csv\"")

Thank you for all your efforts RdotNET team!!!

Dec 25, 2011 at 2:05 PM
Edited Dec 27, 2011 at 7:14 AM

Hello All,

I try to use igraph library of R. when I run my code on small data set, it run well.

but when I use big data set on the same code, at 4th line of my R.Net code an error occurred.

My Code:

NumericMatrix similarity = e.CreateNumericMatrix(similarityMatrix);
e.SetSymbol("simMatrix", similarity);
e.EagerEvaluate("d <- c(1,2)");
e.EagerEvaluate("library(igraph)"); //Error Position
Error Message:
Managed Debugging Assistant 'CallbackOnCollectedDelegate' has detected a problem in 'D:\MohsenCode.vshost.exe'.
Additional Information: A callback was made on a garbage collected delegate of type 'R.NET!RDotNet.Internals.blah3::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

This means that bug happens when you call a method of another library and memory is relatively full.

Please help me. I need this code for my thesis. How Can I do?

jbrownuf07 said that unpublished source code didn't solve this problem. Is there any solution for my problem?