0

I have used SPDisposeCheck tool for SharePoint Visual Studio SharePoint solutions. I want to know is there any such tool available to check SharePoint PowerShell Script object disposal? I have searched but did not come across any. Any help would be appreciated.

Required for SharePoint 2010.

2 Answers 2

0

following script might be useful, In order to use this script, you need to have SPDisposeCheck installed on your machine.

function global:Get-SPDisposeCheck

 {

Write-Host “Recursive check current location …”

$path = $PWD.Path 

#checking actual location recursively 

$Dir = get-childitem $path -recurse 

#all files with dll extension 

$List = $Dir | where {$_.extension -eq“.dll” } 

#made new folder for results 

$export = $path+ “\” + “SPCheck_$((get-date).toString(‘yyyyMMdd-hhmmss’))”

$dir = md $export 

#on every file execute SPDisposeCheck 

$List | ForEach-Object { 

Write-Host$_.Name “is beeing checked…” 

$report = $export + “\” + $_.Name + “.spdisposecheck.txt” 

#in some point, you can use the same dll files, it will be overridden 

& “C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe”$_.fullname | Out-File $report -Force }

#open result folder to review 

explorer $export 

}

Source: SPDisposeCheck equivalent for SharePoint Powershell scripts

http://tomvangaever.be/blogv2/2012/06/run-spdisposecheck-on-all-assemblies-in-a-specific-directory-with-powershell/

1
  • SPDisposeCheck, as you promised in your answer, won´t be able to work for powershell-scripts. It checks only code for assemblies. And the code of assemblies and scripts differ (eg, there is no new SPSite() but Get-SPSite, which DisposeChecker won´t recognize). your link also only shows how to Run Disposechecker to check Libraries using Powershell, but not Checking Powershell-Scripts itself Commented Jul 10, 2015 at 6:27
0

Disposing is nececessary to prevent the process from growing bigger and bigger in memory while lifetime because SPWeb and SPSite objects are not disposed automatically by Garbage Collector. This is necessary especially for the web server process, which runs usually quite long.

However, it is not that crucial in your powershell console. Even if you do not dispose in your powershell, as soon as the powershell is closed all of the memory consumed by the process is released.

3
  • If you write large automated scripts, it is still a good practice to dispose your objects. Commented Jul 10, 2015 at 6:20
  • thats right, but if you do so, you shold be experienced enough to know when and how to dispose the objects. Commented Jul 10, 2015 at 6:25
  • As always with disposal :) Commented Jul 10, 2015 at 6:25

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.