Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell does not release the memory

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?

like image 1000
jjoras Avatar asked Dec 29 '22 05:12

jjoras


2 Answers

Try

 [GC]::Collect()

That enforces garbage collection

like image 110
Dr. belisarius Avatar answered Jan 08 '23 16:01

Dr. belisarius


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()
like image 34
79E09796 Avatar answered Jan 08 '23 16:01

79E09796