Any idea why this simple program (creating powershell session) taking so much memory (~150 MB)?

Question:

I am fairly new to powershell programming. I am creating remote sessions to execute some commands programmatically. However its consuming so much memory (in the order of ~150 to 200 MB). ANd more sessions, its more memory.

Can you please help me figure out the issue?

  1. What is the culprit?
  2. How can i fix it?

Observations:
1. After executing CreateRunSpace command, its consuming around 3MB.


Someone faced the same issue with creating runspaces:

http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/69ccce9d-4696-4886-a5d0-5d2d2e1e4e6d

“Possible PowerShell Runspace Handle Leak”

Still investigating to find the answer though…

Removing pssession made the runspace to release the handles and fixed the memory leak. Its now toggling between ~30 to 40MB.


Thank you!

(FYI – referenced System.Management.Automation.dll)

Answer:

Looks like removing-pssession from the runspace released the memory handles and fixed the leak. Now its taking ~35MB.

Source:

Any idea why this simple program (creating powershell session) taking so much memory (~150 MB)? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply