/// <summary>
        /// 搜索类型集合 静态内存
        /// </summary>
        static Dictionary<string, string> LocationTypeInfoData;        /// <summary>
        /// Tips信息,目前数量不大,放入内存
        /// </summary>
        public static List<Tip> Tips;        /// <summary>
        /// SearchConditionData 缓存键值
        /// </summary>
        static string SearchConditionDataCacheKey = "SearchConditionData";        public static void InitSearchConditionData(object o)
        {
            try
            {
                #region 交通枢纽 地铁站 读取xml
                DataSet ds = new DataSet();
                string fileName = Path.Combine(SimpleConfig.ParentDir, "HotSuggestData.xml");
                ds.ReadXml(fileName);                List<LocationInfo> SearchConditionData = new List<LocationInfo>();
                LocationTypeInfoData = new Dictionary<string, string>();
                if (ds.Tables != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        LocationInfo li = new LocationInfo();
                        li.CityId = ds.Tables[0].Rows[i]["CityId"].ToString();
                        li.DataName = ds.Tables[0].Rows[i]["DataNameCn"].ToString();
                        li.DataID = ds.Tables[0].Rows[i]["DataNameEn"].ToString();
                        li.DataNamePy = ds.Tables[0].Rows[i]["DataNamePy"].ToString();
                        li.Lat = ds.Tables[0].Rows[i]["Google_Lat"].ToString();
                        li.Lng = ds.Tables[0].Rows[i]["Google_Lng"].ToString();
                        li.TagName = ds.Tables[0].Rows[i]["TagNameCn"].ToString();
                        li.TagID = ds.Tables[0].Rows[i]["TagNameEn"].ToString();
                        //li.TypeId = ds.Tables[0].Rows[i]["TypeId"].ToString();
                        li.TypeName = ds.Tables[0].Rows[i]["TypeNameCn"].ToString();
                        li.TypeID = ds.Tables[0].Rows[i]["TypeNameEn"].ToString();                        SearchConditionData.Add(li);                        //type
                        if (!LocationTypeInfoData.ContainsKey(li.TypeID))
                            LocationTypeInfoData.Add(li.TypeID, li.TypeName);
                    }
                }
                #endregion                #region 品牌数据初始化
                DataSet hotelBrands = TipsAccess.GetHotelBrands(null);
                if (hotelBrands != null && hotelBrands.Tables[0] != null && hotelBrands.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < hotelBrands.Tables[0].Rows.Count; i++)
                    {
                        LocationInfo li = new LocationInfo();
                        li.CityId = hotelBrands.Tables[0].Rows[i]["CityId"].ToString();
                        li.DataName = hotelBrands.Tables[0].Rows[i]["HotelBrandName"].ToString();
                        li.DataID = hotelBrands.Tables[0].Rows[i]["HotelBrandID"].ToString();
                        li.DataNamePy = "";
                        li.Lat = "";
                        li.Lng = "";
                        li.TagName = "";
                        li.TagID = "";
                        li.TypeName = "品牌";
                        li.TypeID = "HotelBrand";                        SearchConditionData.Add(li);
                    }
                }
                #endregion                #region 类型
                //行政区,商业区类型
                LocationTypeInfoData.Add("District", "行政区");
                LocationTypeInfoData.Add("Commercial", "商业区");
                //品牌
                LocationTypeInfoData.Add("HotelBrand", "品牌");
                #endregion                #region LoadingTips初始化
                Tips = new List<Tip>();
                DataSet tipsDs = TipsAccess.GetLoadingTips(null, null, null);
                if (ds != null && tipsDs.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < tipsDs.Tables[0].Rows.Count; i++)
                    {
                        Tip tip = new Tip();
                        tip.ChannelID = tipsDs.Tables[0].Rows[i]["ChannelID"].ToString();
                        tip.Content = tipsDs.Tables[0].Rows[i]["Tips"].ToString();
                        tip.ID = tipsDs.Tables[0].Rows[i]["ID"].ToString();
                        tip.ItemID = tipsDs.Tables[0].Rows[i]["ItemID"].ToString();
                        tip.MaxVersion = tipsDs.Tables[0].Rows[i]["MaxVersion"].ToString();
                        tip.MinVersion = tipsDs.Tables[0].Rows[i]["MinVersion"].ToString();                        Tips.Add(tip);
                    }
                }
                #endregion                CacheHelper.CurrentCache.Cache.Set(SearchConditionDataCacheKey, SearchConditionData);
                Common.DefaultLogger.DebugFormat("InitSearchConditionData success!All SearchConditionData count is {0}", SearchConditionData.Count);
            }
            catch (Exception ex)
            {
                Common.DefaultLogger.DebugFormat("InitSearchConditionData Exception:{0}", ex.Message + ex.StackTrace);
            }
        }

解决方案 »

  1.   

    执行过程中内存增加是很正常的,不一定是内存泄露,也可能是你的容器中的数据越来越多,比如LocationTypeInfoData等的元素越来越多,你可以输出LocationTypeInfoData.Count观察数量是否在不断增加,而且内存增加也可能是因为GC回收垃圾不及时引起的,你可以主动调用GC.Collect()之后再观察内存使用量,是否增加,