Author | Message | Time |
---|---|---|
Topaz | 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? | July 11, 2005, 4:50 PM |
Dyndrilliac | Make a call to ExitProcess(). | July 11, 2005, 5:43 PM |
Adron | 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? | July 11, 2005, 11:10 PM |
Topaz | Then I should Unload all of them then End? I'm sure I unloaded all of them. | July 13, 2005, 4:51 PM |
warz | Should be able to simply End your main form. | July 14, 2005, 2:01 AM |
Grok | [quote author=Topaz link=topic=12172.msg120520#msg120520 date=1121273518] Then I should Unload all of them then End? I'm sure I unloaded all of them. [/quote] How sure are you? In your main form's Unload, try this: [code] 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 [/code] 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. | July 19, 2005, 3:43 PM |
Myndfyr | OT: [quote author=Grok link=topic=12172.msg121219#msg121219 date=1121787781] How sure are you? [/quote] *blink* GROK! | July 19, 2005, 6:21 PM |
DDA-TriCk-E | 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. | August 16, 2005, 11:32 PM |
Elneroth | 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. [code]Public Sub Form_Unload() End End Sub[/code] | October 13, 2005, 11:36 PM |
Grok | [quote author=Elneroth link=topic=12172.msg130927#msg130927 date=1129246579] 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. [code]Public Sub Form_Unload() End End Sub[/code] [/quote] 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. | December 8, 2005, 8:50 PM |
rabbit | You should really For Each through your forms calling Unload on each. | December 9, 2005, 1:32 AM |
FrOzeN | 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. :) | December 9, 2005, 5:16 AM |
Adron | What about a form containing this code? [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 [/code] I have a feeling that will not unload willingly while the loop is running? | December 9, 2005, 6:06 AM |