Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2004

Tip: Looking for answers? Try searching our database.

Finalize doesn't run

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MacDermott - 08 Jun 2004 04:22 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.