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.
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.