开发者

Powershell does not release the memory

开发者 https://www.devze.com 2023-01-24 00:44 出处:网络
When running this script from Powershell or Batch: find and replace characters in Windows XP (Powershell 1.0) all goes well. But after script has stopped processing a text file, Powershell开发者_如何学

When running this script from Powershell or Batch: find and replace characters in Windows XP (Powershell 1.0) all goes well. But after script has stopped processing a text file, Powershell开发者_如何学运维 still holds over 1 000 000 kb memory (when inspected from taskmanager) and it does not seem to release the memory usage. I'll have to kill the Powershell process to free up the memory. How to prevent this huge memory usage?


Try

 [GC]::Collect()

That enforces garbage collection


It seems that there is a memory leak in Get-Content.

[GC]::Collect didn't work in our case when loading ~6000 documents and we had to use a StreamReader instead:

$sr = New-Object System.IO.StreamReader($filepath)

...

$sr.Dispose()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号