I'm writing some scripts that will process a large quantity of items and have naturally split out some parts of it to functions. Within these functions I'll get a Sitecore item in a local variable, do some stuff with it and then exit.

Having seen how some of my other scripts consume huge amounts of memory I'd like to be sure these local items are released from memory when out of scope. Is this the case, or do I need to do something manually?

1 Answer 1


SPE creates a runspace using the Windows PowerShell API. While I can't speak to the specifics of how Windows PowerShell manages memory, I can say that functions executed within the same session will accumulate in memory.

From the ISE you can manage how sessions are used whenever you run a script. There is even a Toolbox item to see which session are running.


SPE will automatically clear out the sessions after some period of time; I believe 30 min by default.


  • Manually clear out the session using the PowerShell Background Session Manager
  • Change the setting in the ISE to dispose after each script execution.
  • Use commands such as Clear-Variable and Remove-Variable.
  • Do nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.