BrianBeck
asked on
(VB) Set frm = Nothing --> Why needed?
Dear Gurus
My VB6 app has about 50 forms. An OCX supplier recenly sent me some sample code for his product, and each of the forms had
Set frm = Nothing (with 'frm' being the specific name of each form)
in the unload routine.
I was wondering why such code is useful?
(I understand from
https://www.experts-exchange.com/questions/20892511/Set-frm-Nothing.html?sfQueryTermInfo=1+form+noth+set
that the code is designed to free resources - but doesn't VB automatically do that when forms are unloaded??)
THanks in advance
My VB6 app has about 50 forms. An OCX supplier recenly sent me some sample code for his product, and each of the forms had
Set frm = Nothing (with 'frm' being the specific name of each form)
in the unload routine.
I was wondering why such code is useful?
(I understand from
https://www.experts-exchange.com/questions/20892511/Set-frm-Nothing.html?sfQueryTermInfo=1+form+noth+set
that the code is designed to free resources - but doesn't VB automatically do that when forms are unloaded??)
THanks in advance
if there is some variable of the name frm set to the form itself, you need that, unless the form will remain in memory, and the application will become invisible to the user as application, but still show up in the process list.
ASKER
Hi angelIII
THanks, and while I understand the second half of your answer, I havn't quite worked out what 'if there is some variable of the name frm set to the form itself,' means - can you please elaborate, usefully with a simple example.
Regards
THanks, and while I understand the second half of your answer, I havn't quite worked out what 'if there is some variable of the name frm set to the form itself,' means - can you please elaborate, usefully with a simple example.
Regards
in vb, you can declare a variable:
dim v as <data type>
or
public gV as <data type>
you could do that for the form itself
public frm as frm
declaring a variable of the type of the form itself.
now, even if you don't do that, vb6 does this for you in the background anyhow as soon as you access the form implicitely.
is your form (frm) the project startup module?
or do you start the form with the frm.Show
-> the frm variable is implicitely created in the background by the vb compiler
--> you need to clear it explicitely to be 100% sure.
dim v as <data type>
or
public gV as <data type>
you could do that for the form itself
public frm as frm
declaring a variable of the type of the form itself.
now, even if you don't do that, vb6 does this for you in the background anyhow as soon as you access the form implicitely.
is your form (frm) the project startup module?
or do you start the form with the frm.Show
-> the frm variable is implicitely created in the background by the vb compiler
--> you need to clear it explicitely to be 100% sure.
ASKER
Hi angelIII
Thanks, and on start up, the main form activates, showing its menus etc. Users can then click a menu item that calls up sub forms - and all these sub forms are called using the standard frm.Show method.
Just to clarify:
1. On application startup, is an instance of each form assigned to their respective 'implicitly declared variable'?
2. Or, is the '.Show' method allocating memory for the form, and implicitly assigning it to that variable?
It seems to me that the 'set frm = nothing' may not be needed. I've not used used it for years, so am unclear as to whether I should start to use it. You see, if I start to use this method, do I need to be extra careful in situations where a sub form calls another sub form? Or, will VB6 happily deal with these mattes in its regular 'garbage collection'?
Thanks, and on start up, the main form activates, showing its menus etc. Users can then click a menu item that calls up sub forms - and all these sub forms are called using the standard frm.Show method.
Just to clarify:
1. On application startup, is an instance of each form assigned to their respective 'implicitly declared variable'?
2. Or, is the '.Show' method allocating memory for the form, and implicitly assigning it to that variable?
It seems to me that the 'set frm = nothing' may not be needed. I've not used used it for years, so am unclear as to whether I should start to use it. You see, if I start to use this method, do I need to be extra careful in situations where a sub form calls another sub form? Or, will VB6 happily deal with these mattes in its regular 'garbage collection'?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.