|
-
Sep 19th, 2000, 02:15 PM
#1
Thread Starter
PowerPoster
I have alot of global varaiables and arrays that I do not necessarily need to have active the length of the application.
Upon exit, I have read to set all objects equal to nothing.
What's the correct way of setting all variables equal to nothing? I've tried "set x = nothing", but VB expects an object? Is this necessary?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 19th, 2000, 02:29 PM
#2
Hyperactive Member
Only concern yourself with Object Variables
In your example, if x was declared as a String then it won't work. Just do nothing with these ones. If you have an object variable, which means you declared something like
Code:
Dim myObj as Collection
Then you could/should (?) follow the principal of setting this to nothing once your program is finished with it.
[code]
Set myObj = Nothing
[code]
Note that to test if it is already Nothing, use:
[code]
If myObj is Nothing Then
[code]
With other variables, Stirngs and Variants in particular could be set to the equivalent to nothing. String can be set to "" and variants to "" or Null.
Hope it helps
-
Sep 19th, 2000, 02:35 PM
#3
Thread Starter
PowerPoster
Appreciate the help, but,
What about arrays, integers, and bytes?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 19th, 2000, 03:02 PM
#4
Monday Morning Lunatic
All non-object variables are deallocated when they go out of scope. That includes arrays, even of user-defined types.
I think Objects are deallocated when you set them to Nothing, not when they go out of scope.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 19th, 2000, 09:56 PM
#5
Hyperactive Member
More info
I took from your original request that you wanted to know about how to let VB know you have finished with your global variables before the program ends.
Generally this shouldn't be necessary because globals should be used for variables that are important throughout your entire app.
If you ever do want to get rid of a global array during runtim I imagine you simply ReDim it to 0
Code:
'declare the array as being able to resize
Dim BigArray() as String
...
' set the array size
ReDim BigArray(2000)
...
' set the ne array size
ReDim BigArray(0)
I believe that VB will get around to garbage collecting the old array space so that the memory taken up by the elements will eventually return to the memory pool.
As far as integers/bytes etc, these are not going to take up less space no matter what value you give them.
I can find the MSDN documentation if you like. Also, it will be in almost any VB programmers guide if you want to know for sure all the "rules"
Regards
-
Sep 20th, 2000, 09:09 AM
#6
Thread Starter
PowerPoster
Thanks Paul, Thank all
I appreciate all your help.
Paul, the reson for my question was to ensure that the program releases all memory it can before closing.
ie forms set to nothing
Thank you for your reply.
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|