2

我有两个非常简单的 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(',');
}
4

1 回答 1

0

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

于 2012-10-01T18:59:30.200 回答