Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用CredSSP时PowerShell内存泄漏_C#_Powershell_Memory Leaks_Credssp - Fatal编程技术网

C# 使用CredSSP时PowerShell内存泄漏

C# 使用CredSSP时PowerShell内存泄漏,c#,powershell,memory-leaks,credssp,C#,Powershell,Memory Leaks,Credssp,我想编写一个代码来使用“Powershell”并通过“CredSSP”身份验证创建一个新会话 但是当我监视这个控制台的内存使用情况时,我发现了一些无法处理的东西。。。因此,内存使用量增长缓慢 在我使用ANTS检查内存泄漏后,我发现关键点是“credssp”, 但我找不到处理它或清理这个物体的方法 有人有好主意吗?非常感谢 另外,我的环境是:.NET3.5,PowerShell2.0,VS2010,Windows7SP1 class Program { static void Main(s

我想编写一个代码来使用“Powershell”并通过“CredSSP”身份验证创建一个新会话

但是当我监视这个控制台的内存使用情况时,我发现了一些无法处理的东西。。。因此,内存使用量增长缓慢

在我使用ANTS检查内存泄漏后,我发现关键点是“credssp”, 但我找不到处理它或清理这个物体的方法

有人有好主意吗?非常感谢

另外,我的环境是:.NET3.5,PowerShell2.0,VS2010,Windows7SP1

class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i < 10000; i++)
        {
            using (PowerShell powershell = PowerShell.Create())
            {
                powershell.AddScript("$account = \"xxx\"");
                powershell.AddScript("$pwd = \"xxx\"");
                powershell.AddScript("$credential = New-Object System.Management.Automation.PsCredential($account, (ConvertTo-SecureString $pwd -AsPlainText -Force))");
                powershell.AddScript("$sessions = New-PSSession -ComputerName localhost -Credential $credential -Authentication Credssp");
                powershell.AddScript("Remove-PSSession -session $sessions");
                ICollection<PSObject> results = powershell.Invoke();
                Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64);
            }
        }
        Console.Read();
    }
}
类程序
{
静态void Main(字符串[]参数)
{
对于(int i=0;i<10000;i++)
{
使用(PowerShell PowerShell=PowerShell.Create())
{
powershell.AddScript(“$account=\'xxx\”);
powershell.AddScript(“$pwd=\'xxx\”);
powershell.AddScript(“$credential=New Object System.Management.Automation.PsCredential($account,(ConvertTo SecureString$pwd-AsPlainText-Force))”;
AddScript(“$sessions=New PSSession-ComputerName localhost-Credential$Credential-Authentication Credssp”);
AddScript(“删除PSSession-会话$sessions”);
ICollection results=powershell.Invoke();
Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64);
}
}
Console.Read();
}
}

powershell.Dispose()
?您好,谢谢您的回复,但我已经使用了“使用”,它应该是自动释放的,实际上我已经尝试添加了“powershell.Dispose()”,但它也不起作用。您好,Mathias,是的,我认为它的条件几乎相同,但即使没有例外,它仍然是内存泄漏。英雄联盟