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.
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)
- Common Coding Issues When Using the SharePoint Object Model http://msdn.microsoft.com/en-us/library/bb687949.aspx
- Best Practices: Using Disposable Windows SharePoint Services Objects http://msdn.microsoft.com/en-us/library/aa973248.aspx
- SPDisposeCheck Code Review utility for SharePoint developers to help prevent memory leaks in their custom code http://code.msdn.microsoft.com/SPDisposeCheck
- Dispose Patterns By Example http://blogs.msdn.com/rogerla