|
-
Jan 31st, 2000, 07:48 AM
#1
Thread Starter
Fanatic Member
Hi all.
When ending a VB program, is it best to unload all of the program's Forms? Or is using the End statement enough?
The reason that I am asking this is my program hesitates closing for a few moments when I unload the Forms, but it closes immediately when I use the End statement. However, I thought that it was better to unload the Forms because it frees up the system's memory? 
Any thoughts or suggestions anyone?
Thanks,
------------------
OneSource
The truth may be out there, but it's in here too!
.
-
Jan 31st, 2000, 08:33 AM
#2
Frenzied Member
Microsoft seems to think you should always unload your forms as opposed to Ending the program for normal termination. From MSDN:
The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events offorms andclass modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.
The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.
----------------------------------------
Code:
Dim nFormCollectionIndex As Integer
'Unload any forms that may still be open
For nFormCollectionIndex = (Forms.Count - 1) To 0 Step -1
Unload Forms(nFormCollectionIndex)
Next nFormCollectionIndex
That's all I've got on the subject...
-
Jan 31st, 2000, 08:57 AM
#3
Thread Starter
Fanatic Member
Thanks for the info. Seaweed. 
------------------
OneSource
The truth may be out there, but it's in here too!
.
-
Jan 31st, 2000, 10:06 PM
#4
Thread Starter
Fanatic Member
Hi.
I have a follow-up question on this topic. If M$ recommends that all Forms be unloaded when ending a program, why does my program end so slowly when I unload the Forms while all M$ programs end so quickly? I mean, my program takes longer to end than Word or Excel and it is definitely not bigger than they are. 
Thanks for any thoughts.
Chris
-
Jan 31st, 2000, 10:40 PM
#5
New Member
Due to the fact that VB has to release all created objects and instances of objects, its good memory management and wont freeze your PC. Especially important with 3 tier programming
-
Feb 1st, 2000, 01:50 AM
#6
Thread Starter
Fanatic Member
Thanks SteFlitII.
------------------
OneSource
The truth may be out there, but it's in here too!
.
-
Jun 19th, 2003, 03:06 PM
#7
Lively Member
OneSource,
Something that I have found to be useful.
I unload all my forms as directed by M$. But I then insert an END statement directly after the Unload Statement. This may be over kill, but it seems to help me end program execution faster.
Turtle
-
Jun 19th, 2003, 03:20 PM
#8
If you assume that the computer is just sitting there idling along during those pauses, it makes sense to add the End statement after unloading the forms (I did that once, but I think all those programs have been thrown away a long time ago). However, that seems like a somewhat improbable assumption to make. More likely, there are several components that have to be cleaned up once your forms are unloaded, and the program is exiting, but before it has exited. If you use End, you could leave those objects in memory, but have nothing using them.
-
Jun 19th, 2003, 04:43 PM
#9
Fanatic Member
A couple app's I wrote and terminated using just the END statement, ended up still running in the background. I always unload all forms, then stick an end as the last line in the unload event.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|