Link to home
Start Free TrialLog in
Avatar of johnj_01201
johnj_01201

asked on

PS 4 memory management

Powershell 3/4
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:
[System.GC]::Collect()
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!!!
thank you!
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnj_01201
johnj_01201

ASKER

Although not an answer, the only one given. It turns out that the Powershell ISE keeps EVERYTHING that is sent by write-host and that is what was using up the memory. I had the script showing everything it did. I know use CLS in the main foreach loop to clear the output window.