5

Whenever I open a Powershell prompt either via the built in shell or through ConEmu, Powershell's memory usage is excessively high - usually around 1.5 Gb.

It's worse opening as an Administrator where it jumps between 1Gb and 2Gb roughly every second.

Removing everything from my ~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 file has no effect.

Running [System.Gc]::Collect() takes memory usage down to ~30Mb and it stays that way.

How can I find out what is causing this high usage? Most Powershell memory advice I can find is to do with high usage when running scripts whereas my shell appears to be doing nothing.

Windows 10, Build 1703.

9
  • I wonder if you can get any useful info with a .NET profiler, e.g. bennettadelson.wordpress.com/2013/04/11/…
    – Bob
    Sep 18, 2017 at 16:19
  • Good idea! The majority of the memory is take up by Reflection - Emit.OpCode, RuntimeMethodInfo. That leaves me none the wiser about what's using reflection though!
    – dig412
    Sep 19, 2017 at 9:33
  • Hm. Loaded modules? Anything custom? Get-Module should give you a list of loaded ones. Did this start recently?
    – Bob
    Sep 19, 2017 at 10:06
  • It started a few weeks ago, possibly since I installed Creators Update, but i'm not certain. There's no custom modules, only Microsoft.PowerShell.Utility and PSReadline loaded.
    – dig412
    Sep 19, 2017 at 12:45
  • ...I'm out of ideas. I'd suggest raising this over at the official PowerShell forum too — hopefully they can help.
    – Bob
    Sep 19, 2017 at 14:04

1 Answer 1

3

The same issue happened to me today, powershell would pause for about 5 seconds on startup. Turned out it was PSReadline's fault. The command history was too big (about 600MB in my case) and clearing that fixed the issue.

You can find the history file here:

C:\Users\{user}\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline

Edit

Maximum history count can be set like so:

Set-PSReadlineOption -MaximumHistoryCount 1024

2
  • Thanks @Alireza - I can't test this solution as I've since reformatted my machine and the problem went away, but it sounds like a likely candidate.
    – dig412
    Sep 24, 2018 at 9:36
  • @dig412 Didn't realize the post was a year old.
    – Alireza
    Sep 25, 2018 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .