How a 152,206 character PATH can make Windows think it's out of memory #211018
Replies: 3 comments
|
This is a fascinating breakdown, and there is a very specific, documented Windows NT kernel reason why a 152K-character PATH produces Here is the exact technical explanation of what broke under the hood in Windows: 1. The NT
|
|
That sounds like the script added far too many folders to I’d keep only folders that actually contain tools you need, remove duplicate or outdated entries, and avoid adding every nested directory automatically. The fact that several apps started working again after you fixed the script points to the oversized |
|
I could reproduce this, and the numbers line up with your story. Measurements first, interpretation after. Test. From Python I launched child processes with
(python/whoami thresholds were binary-searched; powershell fails somewhere between 32,000 and 32,700; tasklist/ping were only tested at 152,206.) Control: a 152,206-char and a 2,000,000-char variable with a different name, with a normal Interpretation. The break is right at the 32,767-character ceiling of a What you saw in the shell follows from that: at logon the effective About "keep it under 2,048". There is no such Windows limit. That number comes from the old Environment Variables dialog, whose text box truncated long values; it is not a property of Recovery without a reinstall, for anyone who lands here in the same state: cmd.exe still starts. In that window run Quick self-check in PowerShell: $env:Path.Length
[Environment]::GetEnvironmentVariable('Path','User').LengthFor the script itself: instead of appending every directory, create one folder (say |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Question
Body
How a 152K character long PATH broke Windows
For the past 1-3 days, my Windows 11 laptop had been acting weird. Programs kept crashing with
0xC0000017(*akaSTATUS_NO_MEMORY), even though i still had plenty of RAM available. And apps like Task Manager, PowerShell, Control Panel, and more where failing, and some programs only crashed when launched as administrator.Also, things got worse when Control Panel stopped working, and trying to enter WinRE caused a blue screen. The blue screen's message said something like "Your device has run out of memory" and mentioned that it couldn't allocate enough memory in it's description.
Eventually, i found something very wrong with my user-level PATH. It was 152,206 characters long and contained 6,048 occurrences of
undefined. Meanwhile, the machine-level PATH was completely fine.Click for example of generated PATH
I had a script that automatically added every directory containing an
.exefile underF:\Apps\to my user PATH. It was scanning way too much, including directories that where unnecessary large likenode_modules, and filling PATH with useless entries.After i added restrictions for what directories it scans, i restarted my laptop and everything that was crashing suddenly started working.
Apps like CMD, PowerShell, Task Manager,
tasklist.exeandtaskkill.exe, DISM, SFC, and more finally launched without errors.And my keyboard's key mismatch was fixed.
I ran DISM and SFC afterward, both completed successfully and SFC reported no integrity violations.
I suspect the enormous PATH was responsible for most of the failures because so many things started working immediately after i fixed it. The WinRE blue screen also mentioned memory allocation, but i never recovered the exact stop code because it restarted so quickly, so i can't say for certain that the PATH caused that WinRE crash.
It's honestly ridiculous that a script meant to make executable directories easier to access ended up generating a 152K character long environment variable and ended up making Windows behave like it had run out of memory.
Has anything like this ever happened to you??
And at last, If you'd like to see the code, click here.
Guidelines
All reactions