Re: Out of memory by Jezebel
Jezebel
Fri Feb 17 15:07:50 CST 2006
Put a messagebox or debug.print statement in the form's Terminate event, and
check that it really does terminate. (And similarly for any class modules
you may have.) The sorts of things that will form from unloading are
variables that point to objects on the form itself -- such as a variable
containing a reference to a form control.
"Jes" <Jes@discussions.microsoft.com> wrote in message
news:0BFB7C61-4B9F-43EB-8C4E-5CD1AAAF5C50@microsoft.com...
> Hi Jezebel,
>
> Thanks!
>
> Right, is must be my pure garbage collection skills.
>
> I now have the following code:
>
> Dim pForm As UserFormTUSKrav
> Private Sub Document_New()
> Set pForm = New UserFormTUSKrav
> pForm.initUserFormTUSKrav
> Unload pForm
> Set pForm = Nothing
> End Sub
>
> Private Sub Document_Close()
> Set pForm = New UserFormTUSKrav
> pForm.initUserFormTUSKrav
> pForm.saveDoc
> Unload pForm
> Set pForm = Nothing
> End Sub
>
> But I still get the same error message - "out of memory". when several
> instances of the template has been run.
>
> Any ideas?
> /Jes
>
> "Jezebel" skrev:
>
>> Almost certainly the problem is that your code isn't cleaning up
>> properly.
>> Yes you need to unload your forms. Hard to make specific suggestions
>> about
>> code structure; but better than 'Unload me' within the form is for the
>> calling code to take care of it, eg ---
>>
>> Dim pForm as frmMyForm
>>
>> Set pForm = new frmMyForm
>> pForm.Show
>> :
>>
>> unload pForm
>> Set pForm = nothing
>>
>>
>> In other words, treat all forms as objects: instantiate them and destroy
>> them as needed. A basic prinicple of object-oriented coding is that
>> objects
>> are never responsible for their own lifespans. Thus a form should never
>> try
>> to destroy itself.
>>
>