我创建了运行“Power Shell 脚本”脚本的函数。我使用 Pipeline 和 Runspace ro 运行脚本(例如:power shell get-service)并运行 1.000.000 次脚本“get-service”我看到: - 当运行 1 个脚本(1 个管道和 1 个运行空间)时,应用程序的内存大约是300MB,运行完成时,ram 大约是 70MB - ## Heading ##当运行 2,3,4 脚本(带有 2,3,4 管道和 2,3,..)然后应用程序的 ram 非常高,它是内存泄漏,ram 大约 1GB,.. 和 >2gb。我从这个位置看到问题:当事件 pipelineExecutor_OnDataReady 进程时,调用此函数时 ram 已启动:ConvertToDataTable()
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 (hoang.cntt@gmail.com)