我创建了运行“Power Shell脚本”脚本的函数。 我使用Pipeline和Runspace ro run脚本(例如:power shell get-service)并运行1.000.000次脚本“get-service” 我看到: - 当运行1脚本(1个管道和1个运行空间)时,应用程序是大约300MB,运行完成后,内存大约70MB - ##标题##运行2,3,4脚本(与2,3,4管道和2,3,..)然后应用程序的ram是如此高度,它是泄露的内存,RAM约1GB,..和> 2GB。 我看到的问题,从这个位置:当事件pipelineExecutor_OnDataReady过程中,RAM高达调用该函数时:ConvertToDataTable()我创建了运行“Power Shell脚本”脚本的函数
DataTable dtTable
private void ConvertToDataTable(PSObject psObject, String host)
{
DataRow dr = dtTable.Rows.Add();
foreach (PSPropertyInfo item in psObject.Properties)
{
string strvalue = string.Empty;
if (item.TypeNameOfValue != "System.Runtime.InteropServices.SafeHandle")
if (item.Value != null)
{
if (item.Value.GetType().FullName == "System.ServiceProcess.ServiceController[]")
{
ServiceController[] sController = (ServiceController[])item.Value;
foreach (ServiceController sCtrler in sController)
{
if (sCtrler.MachineName != ".")
strvalue += sCtrler.ServiceName + ", ";
}
if (strvalue.Length > 2)
strvalue = strvalue.Remove(strvalue.Length - 2);
`enter code here`strvalue = "{ " + strvalue + " }";
}
if (item.Value.GetType().BaseType.FullName == "System.Array")
{
var result = ((System.Collections.IEnumerable)item.Value).ToString();
strvalue = string.Join(", ", result);
if (!string.IsNullOrEmpty(strvalue))
strvalue = "{ " + strvalue + " }";
}
else
strvalue = item.Value.ToString();
if (selectedColsList.Contains(item.Name))
dr[item.Name] = strvalue;
}
}
}
4 pipeline run 4 script with each script will run script 1000.000 times get-service and result of script from psoject will add into table, each table 100.000. I see when access to property of psoject then ram is up, if comment call ConvertToDataTable()function, ram is ok.
Please help me.
thanks
Hoang ([email protected])