• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

(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
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Controls/Q_20892511.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
0
BrianBeck
Asked:
BrianBeck
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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.
0
 
BrianBeckAuthor Commented:
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
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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.

0
 
BrianBeckAuthor Commented:
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'?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to clarify: it's 2.
vb6 does not have a garbage collector, every variable contents that is set to nothing is destroyed immediately
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now