Solved

PS 4 memory management

Posted on 2014-01-03
2
166 Views
Last Modified: 2014-01-07
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!
0
Comment
Question by:johnj_01201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39755221
Inefficient powershell code also consumes more memory.
Foreach code also should be looked at to solve memory issue.
0
 
LVL 1

Author Closing Comment

by:johnj_01201
ID: 39762250
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question