In this article I am trying to explain object disposal in Power Shell. Most of us are aware of object disposal in SharePoint object model. In scenarios in which we use SharePoint objects extensively-for example, in SharePoint sites that use custom Web Parts or event handler etc.it can cause the following unusual behaviors if we are not disposing of SharePoint objects once we finished with the operation. The following are the main causes if you don't dispose SharePoint objects properly in custom coding.
Similarly in Power shell scripting also we have to adopt disposal practices to avoid memory leakage resulting in performance issues on your servers. We have two methods for disposal practice
Explicitly dispose every object you create Please find one example for explicit dispose $template = Get-SPWebTemplate "STS#0" New-SPSite -Url "your Site collection URL" -OwnerAlias "domain\user" -Template $template $template.dispose() SpAssignment Any objects defined between the Start-SPAssignment –Global and Stop-SPAssignment –Global commands will be automatically disposed of by PowerShell.You don't have to explicitly dispose each object you created Start-SPAssignment –Global $template = Get-SPWebTemplate "STS#0" New-SPSite -Url "your Site collection URL" -OwnerAlias "domain\user" -Template $template Stop-SPAssignment –Global
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: