Making sure VB program leaves memory when done. 
Author Message
 Making sure VB program leaves memory when done.

Hello all.

I know this has been answered here before, but I still don't get it.

I want to make sure that when a VB4.0 16 program is shut down by the
user, it really truly goes away.  I have been able to put :

  Unload form1
  Set form1 = nothing
  End

into the Exit Click event, and the program will go away nicely.

The same code in the "terminate" event of the main form doesn't seem
to get the job done.

I don't know what to do to make sure that I properly close all the
forms and modules, etc. when the user just double clicks the little
box in the upper left hand corner (win 3.1 style) to end the program.
It seems like parts of the program remain in memory.  I have a very
useable (otherwise) program that I use daily for my work, but I have
to restart windows every time I leave the program to be sure that bad
things won't happen.  If I run and then exit the program three times,
I get a gpf.  I also can't use any of the database files that the
program accesses until I restart windows if I exit using the upper
left box thing.  If I am sure to stop the program using the Exit pull
down on the form, then it doesn't cause trouble.  I'm sure this is a
dumb question, but It's escaped me.  Thanks for your time in answering
this (probably for the ump{*filter*}th time!)

If it wouldn't be too much extra trouble, please e-mail your response
as well as posting to this group to be sure that I actually see it.
Thanks in advance.

Jim Harrison

Please excuse my spam retardant signature
To actually e-mail me, take out the /nospam/
(including the slashes)



Mon, 08 May 2000 03:00:00 GMT  
 Making sure VB program leaves memory when done.


Quote:

>I don't know what to do to make sure that I properly close all the
>forms and modules, etc. when the user just double clicks the little
>box in the upper left hand corner (win 3.1 style) to end the program.
>It seems like parts of the program remain in memory.

Put the code in the Unload event for the form in which that the user
is clicking the button.

Stu



Mon, 08 May 2000 03:00:00 GMT  
 Making sure VB program leaves memory when done.


Quote:

><Hello all.
><
><I know this has been answered here before, but I still don't get it.
><
><I want to make sure that when a VB4.0 16 program is shut down by the
><user, it really truly goes away.  I have been able to put :
><  
><  Unload form1
><  Set form1 = nothing
><  End
><
><into the Exit Click event, and the program will go away nicely.
><
><The same code in the "terminate" event of the main form doesn't seem
><to get the job done.
><

This code on the Form_Unload event will do the job you need to be
done:
        Set form1 = nothing
        End


Mon, 08 May 2000 03:00:00 GMT  
 Making sure VB program leaves memory when done.

Thanks to all who e-mailed or otherwise replied to my plight.

I think I get it now :)

I also found a little reference to this in Microsoft's site.  If I use
a combination of what I was doing (Set form1 = nothing) as well as
what Microsoft says which was:

Dim i as integer
While forms.count > 1

'Find first form besides "me" to unload
i = 0
While Not (Forms(i) Is Me)
i = i + 1
Wend
Unload forms(i)
' my little addition to their recommendation
Set forms(i) = nothing
Wend

'Last thing to be done..
Unload Me
End

....and I put this into the unload event of the form that will trigger
my application's exit.  Then all seems to work just fine.

Thanks again to all who helped.

Jim

Please excuse my spam retardant signature
To actually e-mail me, take out the /nospam/
(including the slashes)



Mon, 08 May 2000 03:00:00 GMT  
 Making sure VB program leaves memory when done.

Hi Jim
There is a hitch in unloading all forms in this manor.
Due to the way the Forms.Count is updated on each Unload
you'll will only unloading every other Form when count from
1 to Forms.Count - 1
So what you need here is to do it backwards
ie: For x = Forms.Count -1 to 1 Step - 1
I also got a Error when the count was adjusted and I was
still trying to Unload Form(x) that was no longer there.
Hope this helps.
Don


Quote:

> Thanks to all who e-mailed or otherwise replied to my plight.

> I think I get it now :)

> I also found a little reference to this in Microsoft's site.  If I use
> a combination of what I was doing (Set form1 = nothing) as well as
> what Microsoft says which was:

> Dim i as integer
> While forms.count > 1

> 'Find first form besides "me" to unload
> i = 0
> While Not (Forms(i) Is Me)
> i = i + 1
> Wend
> Unload forms(i)
> ' my little addition to their recommendation
> Set forms(i) = nothing
> Wend

> 'Last thing to be done..
> Unload Me
> End

> ....and I put this into the unload event of the form that will trigger
> my application's exit.  Then all seems to work just fine.

> Thanks again to all who helped.

> Jim

> Please excuse my spam retardant signature
> To actually e-mail me, take out the /nospam/
> (including the slashes)



Tue, 09 May 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Making sure a form unloads before a program exits

2. Memory leak in VB program that makes use of word

3. Making a VB Memory Resident Program?

4. Not sure if can be done with VB5

5. Virtual memory doesn't reclaim memory from VB program

6. Making sure word isn't running

7. Calling COM EXE from VB.NET Service leaves COM EXE in Memory

8. Making sure XML DLL is installed correctly?

9. Making Sure a Form is Displayed

10. Q: Making sure disconnected RS is used?

11. Making sure application only loads once when loading files

12. VB 3 on Win 98 - Out of Memory when making

 

 
Powered by phpBB® Forum Software