Question:
I’ve got a (long-running) script that I’m trying execute. Unfortunately, as it runs, the memory usage of powershell begins to creep up. The script is relatively simple, and I can’t see any obvious memory leaks. However, I am using an API which may be poorly behaved.
Is there an easy way to get the in-memory size of an object from within powershell, so I can see if my suspicions are correct?
Answer:
Perhaps a crude way to do would be something like this:
1 2 3 4 5 |
$memBefore = (Get-Process -id $pid).WS # Create object here... $memAfter = (Get-Process -id $pid).WS ($memAfter - $memBefore) / 1KB |
If it is a memory leak you might be able to mitigate it with:
1 2 |
[gc]::Collect() |