调用Web Service时服务器端内存泄漏

时间:2012-09-29 14:56:27

标签: c# web-services memory-leaks server-side

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

1 个答案:

答案 0 :(得分:0)

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