COM Interaction

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
 
C

Christophe Lephay

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top