Reputation: 65
I have a VB6 code that call C# by using late binding, when the C# finish the VB6 doesn't release the C# reference, i tried implementing in the C# IDisposable i tried setting the the reference to nothing and it didn't work
Is it possible that the VB6 code doesn't release the ref? Is there any other way to release all reference to the C# code? Is there any annotation i might use?
To give the whole story the VB6 is third party code, i cant add functionality/code call to it.
Thanks X
VB6
Private Sub Command1_Click()
Dim obj As Object
Set obj = CreateObject("test1.class1")
obj.msg
Set obj = Nothing
End Sub
C#
namespace test1
{
[ClassInterface(ClassInterfaceType.None)]
public class Class1 : IDisposable
{
public void msg()
{
Console.Write("msg");
}
~Class1()
{
Console.Write("~Class1");
}
public void Dispose()
{
Console.Write("Dispose");
}
}
}
Upvotes: 1
Views: 485
Reputation: 941327
This is simply not the way memory management works in managed code. The rules don't change just because you expose it as a [ComVisible] class. Your vb6 code will release the CCW (COM callable wrapper). But that just removes a reference to the C# object. The object doesn't get destroyed and the finalizer won't run until the garbage collector runs. Which in your posted snippet won't happen until the program terminates, you are not allocating enough managed objects to trigger a GC.
This is not a problem.
Upvotes: 6