We are working with QTP for the past 6 years and we did not have the necessity to declare variables. Off late while executing tests in QTP, we are getting some memory problems. Some of our engineers suggested that we were not declaring variables and then destroying it in the end and because of that we are facing hat problem. We have around 12000 test cases and we are now facing a laborious task of opening each tests, declaring the variables and destroying it in the end. Is this necessary?
Since declaring variables are not mandatory in QTP, would not they have addressed these kind of memory problems internally?
I do understand that QTP and in general VBS as such does not mandate declaring and destroying of variable as such but when it comes down to execution there are many things that come into consideration like Size Of Ram, Number of actions, Call to Actions, Addins being loaded, Size of the tests, Number of variables that are eating up memory and the amount of memory being eaten up by them.
Action1 has 10 Variables each of size 5Bytes = 50Bytes
Action2 has 25 Arrays each cell using 5Bytes.
Now if u don't destroy them the memory is blocked and cannot be reused until it has been freed.
For your question of is it required it is always preferable that at the end of every function destroy the variables if they are not global variables so that memory gets freed. The same memory can be used for some other variable in your next function.
Best way to do that would be put up "OptionExplisit" in your Driver or in your Actions so that u know if there are any variables used that have not been declared.
I would consider this a a new enhancement and it take more efforts than you assume.
If you have segregated your reusable based on function then implement the declarations in function and destroy your variable in the function.
If you have segregated your reusable based on actions so implement the same.
you also need to use the option explicit at the top of your driver script as well as in your actions/vbs file and need to execute all your scripts once.There might be more human errors because of the copy pastes work.
apart from that try to identify the drawbacks in your framework and try to address few based on your budget. in this way you can better justify.
You can't destroy variables within a function: you have to wait for the function to finish executing before the memory allocated for these variables is released - this is done automatically. VBscipt uses variant data types, so I would have said that it wouldn't make a difference declaring them or not.
Have a look through the article Raj posted - it suggests that you use vb script functions instead of actions to reduce memory allocation. If you've done this then perhaps you need to optimise the amount of variables you are using in the code.