I am having an issue with a long running powershell script with a the memory increasing over time, like a leak. I am creating collection variables but after doing a connection to sql. Later on I am writing the output to a CSV file. However in my functions I am setting the collection variables to $null. But the memory keeps going up and up.
Is there something special I am missing on how powershell frees it memory. So for example if I call function a and I have a variable called $test should the memory be free for what was allocated to that function.
So is there any general advice somebody can offer how powershell allocates and frees it's memory, or any other advice that you can offer?
I am even calling the GC::Collect() and it is still not helping
Below is a simplified version of the code.
$data_list = @()
foreach ($pc in $machine_list)
$obj = New-Object System.Object
$obj | Add-Member -MemberType NoteProperty Data1 $pc
$obj | Add-Member -MemberType NoteProperty Data2 $pc
$obj | Add-Member -MemberType NoteProperty Data3 $pc
$data_list += $obj
$data_list | Export-Csv c:\scripts\test.txt -notype
$data_list = $null
$machine_list = @()
#select Name from Table where ProductID = 'XX'
# Then put each Name into a machine_list variable.