When using powerGate to transfer data between the ERP system and a client the memory of the host process can increase in some situations.
The memory can increase more than the size of the file e.g. when using Update-ERPMedia to upload a file.
When the operation has finished executing the memory does not get released immediately. After some time the memory does get released.
This problem is caused by an internal timer used by powerGate that does not get cleaned up right away. The default value for this is 100 seconds. This affects all powerGate cmdlets and also the powerGate .NET library. The issue is noticeable especially when using many memory heavy operations in a short time.
To resolve this issue you can either pause the execution until the timer runs out or reduce the default value of the internal timer.
Let the timer run out
To avoid this issue you can let the idle timer run out. This will release the memory. To do this you could make sure that no data exchange between a client and the ERP system is made for 100 seconds. This could be done by using following code:
Start-Sleep -Seconds 100
Reduce the idle timer
The timer can be changed in your script to avoid this issue. Reducing this timer will clean up the memory earlier and therefore the memory will not increase that fast anymore. The downside is that this impacts the performance, making the execution slower. The default value is 100 seconds. To change the value you can use following code:
[System.Net.ServicePointManager]::MaxServicePointIdleTime = 100
ServicePointManager (Microsoft docs)