Skip to content

Instantly share code, notes, and snippets.

@altrive
Created March 7, 2014 13:39
Show Gist options
  • Save altrive/9411637 to your computer and use it in GitHub Desktop.
Save altrive/9411637 to your computer and use it in GitHub Desktop.
function Main
{
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Net.Http
Write-Host ("Before: {0} MB" -f ([GC]::GetTotalMemory($true) / 1MB))
foreach ($i in 1..1000)
{
Get-ContentFromUrl -url "http://localhost" > $null
}
[GC]::Collect()
Write-Host ("After : {0} MB" -f ([GC]::GetTotalMemory($true) / 1MB))
}
function Get-ContentFromUrl([string] $url)
{
$client = New-Object Net.Http.HttpClient
$task = $client.GetAsync($url)
$task.Wait()
$result = $task.Result
#$client.Dispose() #Should be disposed?
#$task.Dispose()
return $task.Result
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment