COM Interaction

  • Thread starter Thread starter Michaelov, Itzik
  • Start date Start date
M

Michaelov, Itzik

Hello
My very simple class C#:

[ComVisible(true)]
public class ClsStamCOMDLL
{
public ClsStamCOMDLL()
{
System.Windows.Forms.MessageBox.Show("Constructor");
}

~ClsStamCOMDLL()
{
System.Windows.Forms.MessageBox.Show("Finalize");
}

public void aaa()
{
System.Windows.Forms.MessageBox.Show("aaa");
}
}

Now i want use this class from VB6.
Add reference to created TLB
And following my VB6 project:

Dim a As StamCOMDLL.ClsStamCOMDLL
Set a = New StamCOMDLL.ClsStamCOMDLL

a.aaa

Set a = Nothing


The problem:
Why "~ClsStamCOMDLL()" method not fired ?
What about "a" object after set nothing
I fear memory leak...

Thanks
 
Michaelov said:
Hello My very simple class C#:

[ComVisible(true)]
public class ClsStamCOMDLL
{
public ClsStamCOMDLL()
{
System.Windows.Forms.MessageBox.Show("Constructor");
}

~ClsStamCOMDLL()
{
System.Windows.Forms.MessageBox.Show("Finalize");
}

public void aaa()
{
System.Windows.Forms.MessageBox.Show("aaa");
}
}

Now i want use this class from VB6.
Add reference to created TLB And following my VB6 project:

Dim a As StamCOMDLL.ClsStamCOMDLL
Set a = New StamCOMDLL.ClsStamCOMDLL

a.aaa

Set a = Nothing


The problem:
Why "~ClsStamCOMDLL()" method not fired ?
What about "a" object after set nothing
I fear memory leak...

That's the way the garbage collector works. you cannot assume anything about
when it will collect memory back (even if you can force him to do so), and
you cannot even be sure it will : your application can end before the GC
does any collect, and your destructors won't be called in this case.

This won't result usually in memory leak because the memory the GC was
managing will be given back to the OS.

However, you cannot use the the RAII idiom (Resource Acquisition Is
Initialization - automatic acquisition and release of resources using
constructors/destructors calls).
 
Back
Top