Oh my, as I read through Zach’s post, it hit me like a ton of bricks. Not really, but I have been stuck on lyrics lately. The post was very eye opening and one that you need to review if you are using PowerShell and SharePoint. Heck, if you are using PowerShell and any .Net objects that should be Disposed.
“There was a potential for PowerShell users to constantly leak memory without knowing it!“
Compare the following 3 lines of PowerShell Script
PS> $S = New-Object Microsoft.SharePoint.SPSite(“http://sharepoint”)
My SharePoint Site
PS> $S = New-Object Microsoft.SharePoint.SPSite(“http://sharepoint”); $S.Title; S.Dispose()
In the first example there are a total of 3 threads spun up as each PS> will start a new thread. Keep an eye on Zach’s blog for updated work arounds.
SharePoint+PowerShell is (Usually) a Perfect Match - Zach Rosenfield's SharePoint Blog
Don’t forget to take a look at the updated information on Developer Focused SharePoint Best Practices (Roger Lamb’s blog is a great resource for this, link below)