Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:dispose [2015/09/14]
127.0.0.1 external edit
developer:dispose [2015/11/24] (current)
sandy
Line 3: Line 3:
 > **Summary:​** //Discusses variables, their scope, and how to clean them up.// > **Summary:​** //Discusses variables, their scope, and how to clean them up.//
  
-=====Overview===== +VBScript’s garbage collector runs at the end of every statement and procedure, and does not do a search of all memory. Rather, it keeps track of everything allocated in the statement or procedure. If anything has gone out of scope, it frees it immediately.
-VBScript’s garbage collector runs at the end of every statement and procedure, and does not do a search of all memory. Rather, it keeps track of everything allocated in the statement or procedure; if anything has gone out of scope, it frees it immediately.+
  
-Global variables, ones declared outside of a procedure, do not go out of scope until VBScript is reset or destroyed. Thus, for memory efficiency, it is best not use global variables.+Global variables, ones declared outside of a procedure, do not go out of scope until VBScript is reset or destroyed. Thus, for memory efficiency, it is best to not use global variables.
  
-With this said, one can conclude that it is more memory efficient to write scripts that contain ​a number of small, efficient procedures, so variables that are no longer needed are garbage collectedthan it is to write a single, massive procedure.+You can write scripts that contain ​several ​small, efficient procedures, so variables that are no longer needed are garbage collected. This is more memory efficient ​than it is to write a single, massive procedure.
  
-But, sometimes is neither possible nor convenient to write a script in a granular fashion. In such cases, it is possible to manually clean up unused objects and variables along the way to keep your single, massive procedure memory efficient.+But, sometimes ​it is neither possible nor convenient to write a script in a granular fashion. In such cases, it is possible to manually clean up unused objects and variables along the way to keep your single, massive procedure memory efficient.
  
 =====Example===== =====Example=====
-The following example demonstrates how to create a single procedure ​that is capable of cleaning up a number of different variable types. The idea is that when a variable is no longer needed, you can call a single procedure to clean it up, thus making ​your scripts use less memory. ​+The following example demonstrates how to create a single procedure capable of cleaning up several ​different variable types. The idea is that when a variable is no longer needed, you can call a single procedure to clean it up, so your scripts use less memory. ​
  
-For example, lets say your script ​used an array variable to store a massive amount of data. When you were finished with the variable, you could dispose of the array, and recover its memory, like this:+For example, lets say your script ​uses an array variable to store a massive amount of data. When you are finished with the variable, you can dispose of the array, and recover its memory, like this:
  
 <code vb> <code vb>
Line 21: Line 20:
 </​code>​ </​code>​
  
-This examples ​cleans up dictionary objects, arrays, and simple variables. But, it could be extended to include other types of objects, such as file streams, database recordsets, or user-defined class objects.+This example ​cleans up dictionary objects, arrays, and simple variables. But, it could be extended to include other types of objects, such as file streams, database recordsets, or user-defined class objects.
  
 <code vb> <code vb>
developer/dispose.txt · Last modified: 2015/11/24 by sandy