PaulHigin / PSThreadJob

A PowerShell module for running concurrent jobs based on threads rather than processes
MIT License
180 stars 18 forks source link

Change to clean up runspaces after a job ends, and defer runspace init #7

Closed PaulHigin closed 6 years ago

PaulHigin commented 6 years ago

I noticed that when queuing up a large number of jobs, a runspace object is created for each and initialized. Runspaces contain a lot of resources and don't need to be initialized until the queued job is started. So the first change is to defer runspace initialization until job start.

In addition runspaces remain open after the job completes and are removed only when the job is removed. Again, runspaces contain a lot of state and use up memory. They are no longer needed after the job run ends. So the second fix is to dispose of the job runspace after the job ends.