• Welcome to Valhalla Legends Archive.
 

[VB6] Leaving itself in Memory

Started by Topaz, July 11, 2005, 11:50 AM

Previous topic - Next topic

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?

Dyndrilliac

Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

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?

Topaz

Then I should Unload all of them then End? I'm sure I unloaded all of them.

warz

Should be able to simply End your main form.

Grok

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.

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Chriso

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.

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.

Public Sub Form_Unload()
End
End Sub

Grok

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.

rabbit

You should really For Each through your forms calling Unload on each.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

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. :)
~ FrOzeN

Adron

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?