gpt4 book ai didi

c# - 调用 Web 服务时服务器端内存泄漏

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:41 25 4
gpt4 key购买 nike

我有两个非常简单的 web 服务方法,我使用 json 每秒调用一次IIS存在内存泄漏,w3wp进程每秒占用300-400k可以做些什么来阻止泄漏?

方法如下:

[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public List<StationStatus> GetAllStationsValues(string networkID ,string stationIDs)
{
List<StationStatus> stationStats = new List<StationStatus>();
foreach (string stationID in stationIDs.Split(','))
{
if (Application[networkID + "-" + stationID] != null)
{
string[] vals = (string[])Application[networkID + "-" + stationID];

stationStats.Add(new StationStatus() { NetworkID = networkID, StationID = stationID, ComponentName = vals[0].Split(':')[0], LatestValue = vals[0].Split(':')[1], Status = "0" });////////
}
}

return stationStats;
}

[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public string GetValue(string networkID, string stationID)
{
int sec = DateTime.Now.Second;

if (Application[networkID + "-" + stationID] == null)
{
return "";
}

string[] compValues = (string[])Application[networkID + "-" + stationID];


string returnValue = "";

foreach (string compValue in compValues)
{
returnValue += compValue + ",";
}

return returnValue.TrimEnd(',');
}

最佳答案

尝试使用 StringBuilder用于附加到您的 returnValue 字符串的类。

关于c# - 调用 Web 服务时服务器端内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12653765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com