This application that I'm developing is always leaving itself in memory after I close it. I unloaded all the forms and ended it, but it seems to do it anyway. Ideas?
Make a call to ExitProcess().
You could use End to get the same effect, but VB programs are supposed to end by themselves when you unload all forms and return from your Sub Main if you have one. Maybe you're forgetting some form?
Then I should Unload all of them then End? I'm sure I unloaded all of them.
Should be able to simply End your main form.
Quote from: Topaz on July 13, 2005, 11:51 AM
Then I should Unload all of them then End? I'm sure I unloaded all of them.
How sure are you?
In your main form's Unload, try this:
Private Sub Form_Unload(Cancel As Integer)
Dim F As Form
For Each F In Forms
If StrComp(F.Name, Me.Name) <> 0 Then
Unload F
End If
Set F = Nothing
Next
End Sub
If this succeeds in solving our problem, you had a hidden form that did not close like you thought.
If your application is still open after this, you have loaded code running in an object that is held open in a module-scoped variable. Go through your Module1.BAS (or other BAS modules) for any Objects/Variants that might be maintaining an instance of a class. Trace that class' execution by writing debug logs on Initialize and Terminate events. If you have an Init without a Term, there's the problem.
I've had this problem before, I think it was a procedure that was running on Form_Load that told the form to show, the procedure was to downloading a file via Async. I had to make sure it stopped everything before it was unloaded otherwise the form would show itself again.
A lot of people get that problem a lot.
Just add the line End to all the form_unloads you want to end the program when you close them.
Public Sub Form_Unload()
End
End Sub
Quote from: Elneroth on October 13, 2005, 06:36 PM
A lot of people get that problem a lot.
Just add the line End to all the form_unloads you want to end the program when you close them.
Public Sub Form_Unload()
End
End Sub
Please do not suggest this again, it promotes lazy programming by making the programmer not responsible for their code behavior. Using End hides the fact that objects are being created and code invoked yet no proper exit point or deallocation of objects has taken place.
You should really For Each through your forms calling Unload on each.
I'd just like to mention regarding Grok's code.
With StealthBot, a bug had existed for a long time that when you closed StealthBot by clicking 'Exit' in the right-click popup menu in the tray, it would crash giving an error.
StealthBot's code is setup the exact same way as Grok had to Unload each form and Set them as Nothing. And to then call 'End' after, but the problem still existed.
Stealth fixed this by changing 'End' to use ExitProcess(). (As Dyndrilliac said).
Due to this I'd recommend using ExitProcess() to assure avoidance of even the most unorthodox errors that may occur. :)
What about a form containing this code?
Sub Command1_Click()
Static running As Boolean
If running Then running = false: Exit Sub
running = true
Do While running
Sleep 100
DoEvents
Loop
End Sub
I have a feeling that will not unload willingly while the loop is running?