I have a script that is about 900 lines long and reads of record of every in a large database table one record at a time (very complex query).
As the program is running Resource Manager shows the power shell ISE is consuming more and more memory. The program is currently running and the system started of with 2.6GB used memory and is now up to 5.6GB used and slowly growing as the script cycles through each record and does it's processing.
At the top of the script I have:
Which I read would handle al garbage collecting???
I then read others with the same issue get rid of variables and do something like GC::Collect() right afterwards to free the memory, but I have not see any actual examples.
I am not keeping data, just reusing the same variables inside a couple of nested foreach loops. The outer loop cycles through the database tables.
The next loop cycles through each record of whichever table we are on.
Do I need to "destroy" every variable at the end of the foreach loops to keep the memory usage down? How do I destroy a variable?
Please explain because I am on record 10,000 and there's like 2 million more to go!!!