I have a VB.NET DLL, which contains a class I instantiate from a VB 6.0
application.
The instance is named NetTest, and functions very nicely.
When I'm through with it, I execute this line of code in VB 6.0:
Set NetTest = Nothing
I can step through the code and see this line executing.
However, when I put a breakpoint in the VB.NET code, at the Finalize event
of the class, it never fires.
What am I doing wrong?
- Turtle
Christopher Robert - 08 Jun 2004 08:50 GMT
If you search for "garbage collection" or "object lifetime" in MSDN and
elsewhere, you will be treated to long treatises on garbage collection and
all the ways you can't rely on it. I don't remember the specifics for VB6,
and I don't know how .NET COM interop factors in, but my impression is that
you just can't count on Finalize happening any time immediately after your
object becomes unreferenced. (VB.NET adds a new IDisposable interface that
allows for more immediate disposal of objects.)
...Chris
> I have a VB.NET DLL, which contains a class I instantiate from a VB 6.0
> application.
[quoted text clipped - 9 lines]
> What am I doing wrong?
> - Turtle
MacDermott - 08 Jun 2004 12:02 GMT
Thanks for your response!
Yes, I've been treated to some somewhat shorter treatises on that subject.
It looks as if my "outer" applications can't close properly, because they
can't release the reference to the VB.NET object. My guess is that the
Finalize not running might be related to this.
Could you perhaps point me to some code samples on using this IDisposable
interface?
Thanks!
- Turtle
> If you search for "garbage collection" or "object lifetime" in MSDN and
> elsewhere, you will be treated to long treatises on garbage collection and
[quoted text clipped - 19 lines]
> > What am I doing wrong?
> > - Turtle
Christopher Robert - 08 Jun 2004 12:26 GMT
You can try:
http://www.codeproject.com/dotnet/ForDotNetBeginner.asp?print=true
http://www.developersdex.com/csharp/message.asp?p=1111&r=3374518
Not sure if those will help or not, but if you google it there seem to be a
lot more.
Good luck!
...Chris
> Thanks for your response!
> Yes, I've been treated to some somewhat shorter treatises on that subject.
[quoted text clipped - 33 lines]
> > > What am I doing wrong?
> > > - Turtle
Vince Yuan - 25 Jun 2004 14:38 GMT
Finalize is called by the system garbage collection.
When you set nettest nothing, the memory is not destroyed. The garbage
collection will free that memory in future. So finalize() is not called.
You can force system to collection garbage by using: System.GC.Collect()
Vince
> I have a VB.NET DLL, which contains a class I instantiate from a VB 6.0
> application.
[quoted text clipped - 9 lines]
> What am I doing wrong?
> - Turtle