Does PowerShell STA issue fix SharePoint memory leak issue?

Some background:

In short, the standard SharePoint guideline is that COM-supported objects such as SPSite

and SPWeb

should not be used by different threads. This conflicts with the default MTA PowerShell mode confirmed in the Leaked Workarounds article referenced above. One of the recommended solutions to the problem was to try the PowerShell 2.0 -STA flag, which seems to fix the problem; however, in the comments on his post, Zach suggests that STA mode is insufficient.

This is pushing to the edge of my COM knowledge, so I hope someone can help me understand ...

  • Should STA be sufficient to restrict object access to a single thread through PowerShell pipelines?
  • If not, why not?
+2


source to share


1 answer


Ultimately, the -STA mode should be sufficient if you are using Powershell 2.0. The reason for this is that in STA mode, the default space reuses one thread for all interactive commands (and scripts too). It's possible that the version of powershell that Zack watched in February behaved differently than the current RC / RTM from PowerShell 2.0. It may have used UseNewThread instead of the current default, ReUseThread:

PS> [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace

Events                : System.Management.Automation.PSLocalEventManager
ThreadOptions         : ReuseThread
RunspaceConfiguration : System.Management.Automation.Runspaces.RunspaceConfigForSingleShell
InitialSessionState   :
Version               : 2.0
RunspaceStateInfo     : Opened
RunspaceAvailability  : Busy
ConnectionInfo        :
ApartmentState        : STA
InstanceId            : 8d3bfae1-8b64-433d-9ab9-ce640b15f84f
SessionStateProxy     : System.Management.Automation.Runspaces.SessionStateProxy
Debugger              : System.Management.Automation.Debugger

      

In short, you're all right. The best practice he talked about was most likely how to deploy a new workspace using ReUseThread, which is now redundant as this is the default thread option for -STA. However, you can use this technique to run on a single thread in MTA mode; -)



-Oisin

Microsoft PowerShell MVP

+2


source







All Articles