Powershell's Start-sleep causes memory growth

I observed that a loop on below powershell command will cause the memory usage steadily increase:

Write-EventLog -LogName $logName -Source $sourceName -Message "perfLog" -EventId 0 -EntryType information


Does Write-EventLog have memory leak? Or there is any resource cleanup call that I missed? Thanks for any clue.




May 28th, 2015 10:34pm

There are 4 jobs which matches the number of cores on my computer.

The sleep is to control the event generation rate and simulate different system loads caused by event generation. Thanks.


  • Edited by Leonjl Tuesday, June 02, 2015 4:19 PM
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2015 4:18pm

The memory usage stabilize when most memory is used (15G). The system is already very slow because of this. 



  • Edited by Leonjl Wednesday, June 03, 2015 1:54 PM
June 2nd, 2015 11:44pm

I am not (and don't need) using a lot of jobs. I only use 4 jobs on a 4 core with 15G memory - which is a decent machine for windows. This has nothing to do with the heaviness of the jobs. If I remove the sleep, the jobs are heavier and the memory used is much less and stable. Obviously sleep is the trouble maker. If start-sleep is not friendly, is there other way to introduce waiting in powershell? Thanks.




  • Edited by Leonjl Wednesday, June 03, 2015 6:08 PM
Free Windows Admin Tool Kit Click here and download it now
June 3rd, 2015 2:00pm

Start-Sleep does not have a -ms option, try changing to -milliseconds (or -m), see if that makes a difference.  I suspect what is happening is that the error info from all the failed start-sleeps is consuming memory.


  • Edited by RichardEmptage Wednesday, June 03, 2015 2:31 PM
  • Proposed as answer by jrv Wednesday, June 03, 2015 2:58 PM
June 3rd, 2015 2:21pm

Using -milliseconds does not solve the problem.



  • Edited by Leonjl Wednesday, June 03, 2015 5:03 PM
Free Windows Admin Tool Kit Click here and download it now
June 3rd, 2015 5:03pm

Problem solved: 

http://stackoverflow.com/questions/30671343/start-sleep-memory-leak-or-causing-powershell-memory-leak



  • Edited by Leonjl 15 hours 33 minutes ago
  • Marked as answer by Leonjl 15 hours 33 minutes ago
June 6th, 2015 11:38am

Problem solved: 

http://stackoverflow.com/questions/30671343/start-sleep-memory-leak-or-causing-powershell-memory-leak



  • Edited by Leonjl 15 hours 25 minutes ago
  • Marked as answer by Leonjl 15 hours 25 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 6th, 2015 11:40am

So the problem was bad code and not a memory leak or bug. 

June 6th, 2015 1:25pm

Problem solved: 

http://stackoverflow.com/questions/30671343/start-sleep-memory-leak-or-causing-powershell-memory-leak



  • Edited by Leonjl Saturday, June 06, 2015 3:36 PM
  • Marked as answer by Leonjl Saturday, June 06, 2015 3:36 PM
Free Windows Admin Tool Kit Click here and download it now
June 6th, 2015 3:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics