• 拼接xml时出现内存溢出解决办法


     /// designed by Alex
                    /// 解决内存溢出问题,不可使用迭代器和foreach
                    /// 循环遍历List, 别生成xml,一边释放
                    /// 反向遍历,相当于出栈,避免索引顺序乱的问题
                    /// 反转List.
                    if (zrate.RateList != null && zrate.RateList.Count != 0)
                    {
                        log.Debug("反转list");
                        zrate.RateList.Reverse();
                        log.Debug("循环遍历Zrate List 生成xml");
                        int policySize = zrate.RateList.Count;
                        for (int index = policySize - 1; index > -1; index--)
                        {
                            SplitPolicy item = zrate.RateList[index];
                            string strChangePnr = item.IsChangePnr ? "1" : "0";
                            string strCabin = item.Cabin;
                            try
                            {
                                strCabin = strCabin.Replace("/", "");
                            }
                            catch { }
                            decimal c = item.Rate + item.RuleRate;
                            string d = item.IsAutoTicket ? "1" : "0";
                            string strWeekNum = item.WeekNum;
                            if (strWeekNum != "")
                            {
                                strWeekNum = strWeekNum.Replace("/", ",");
                            }
                            string ZtFlightNumber = "";
                            try
                            {
                                ZtFlightNumber = item.ApplyFlightNumber.Replace('/', ',');
                            }
                            catch { }
                            string ZtNoFlightNumber = "";
                            try
                            {
                                ZtNoFlightNumber = item.NotApplyFlightNumber.Replace('/', ',');
                            }
                            catch { }
    
                            string WorkTimeWeekDay = "";
                            string RefundWorkTimeWeekDay = "";
                            //工作时间
                            for (int i = 0; i < 5; i++)
                            {
                                WorkTimeWeekDay = WorkTimeWeekDay + item.WorkTimeWeekDay + ",";
                                RefundWorkTimeWeekDay = RefundWorkTimeWeekDay + item.RefundTimeWeekDay + ",";
                            }
                            //休息日
                            for (int i = 0; i < 2; i++)
                            {
                                WorkTimeWeekDay = WorkTimeWeekDay + item.WorkTimePlayDay + ",";
                                RefundWorkTimeWeekDay = RefundWorkTimeWeekDay + item.RefundTimePlayDay + ",";
                            }
    
    
                            info.Append("<Item Id='" + item.ID + "' State='" + item.Status + "' IsChangePnr='" + strChangePnr + "' ");
                            info.Append("ProviderWorkTime='" + WorkTimeWeekDay.Trim(',') + "' PorviderVWorkTime='" + RefundWorkTimeWeekDay.Trim(',') + "'>");
                            info.Append(item.DepartCode.Replace("/", ",") + "|" + item.ArriveCode.Replace("/", ",") + "|" + item.AirCompany + "|" + item.TripType + "|");
                            info.Append(ZtFlightNumber + "|" + ZtNoFlightNumber + "|" + strWeekNum + "|" + item.TicketType + "|");
                            info.Append(strCabin + "|" + c.ToString("0.000") + "|" + item.SaleBeginTime.ToString("yyyy-MM-dd") + ",");
                            info.Append(item.SaleEndTime.ToString("yyyy-MM-dd") + "|" + item.TravelBeginTime.ToString("yyyy-MM-dd") + ",");
                            info.Append(item.TravelEndTime.ToString("yyyy-MM-dd") + "|" + item.OfficeID + "|");
                            info.Append(item.AddTime.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "|" + item.ModifyTime.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "|");
                            info.Append(item.SupplierCode + "|" + item.Remark + "|" + d);
                            info.Append("</Item>");
    
                            //同时remove item
                            zrate.RateList.RemoveAt(index);
                            //每10000条调用一次gc,回收前一百条被remove的数据
                            if (0 == index % 10000)
                            {
                                GC.Collect();
                            }
                        }
                    }
                    else
                    {
                        log.Error("zrate里的RateList为空!");
                    }
                }
                else
                {
                    info.Append("<OTA_Alter_AirFareRS>");
                    info.Append("<Error Code="" + zrate.Msg + "" ShortText="" + zrate.Msg + "" />");
                }
                info.Append("</OTA_Alter_AirFareRS>");
    
                //WriteLog.WriteErrorLogDataInteraction(info.ToString(), "变动政策返回信息");
                log.Debug("返回xml成功");
                return info.ToString();
  • 相关阅读:
    javascript 注意事项汇总
    Object.prototype.toString方法
    PHPStorm使用心得
    JavaScript基于原型链的继承
    PHP重定向的3种方式
    Android应用与开发环境
    PHP时间处理
    cocos2dxna 游戏中如何控制后退键实现目的性跳转
    wp7 独立存储空间在真机和虚拟机测试的时候数据不一样
    c#获取交叉数组的行、列数
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3488643.html
Copyright © 2020-2023  润新知