炮哥:"嘿,哥们,忙啥呢,电脑卡成这逼样。"

勇哥:"在用CLR Profile工具分析下FlexiPrint的内存占用情况。"

炮哥:“哎哟,不错啊,玩高级的了。”

勇哥:“也没有啊,就是发现点击查询按钮查询数据时,如果数据量一大的话,内存上上升了好几个M,所以第一感觉就不太正常。正好以前也了解过CLR Profile,但一直没怎么具休的用过,这次正好拿来研究研究。”

炮哥:“Nice job,要向你学习,能够主动发现问题并研究解决方法。对了,有什么发现么?”

勇哥:“通过工具发现dgMain_CellFormatting方法占用内存过多。”

炮哥:“这个方法干嘛用的,要这么多的内存?”

勇哥:“其实做的事情很简单,根据每行订单的不同状态,显示不同的图标,以便让客户能够很直白的了解订单的状态。”

炮哥:“噢,是这样,那确实没什么,让我看下代码。”

namespace IPP_PCL.HomeViewUserControl
{
public partial class PrintOrderInformationUserControl : UserControl, IHomePrintOrderInformationView
{
#region Field private readonly PrintCellLiteServiceClient _serviceClient = new PrintCellLiteServiceClient(); #endregion #region Event Handler /// <summary>
/// 此事件主要用于图片按钮的显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgMain_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dgMain.Columns[e.ColumnIndex].Name.Equals("dgMain_PrintIcon"))
{
int row = e.RowIndex;
//获取展示图片按钮的单元格
string status = dgMain.Rows[row].Cells["dgMain_statusKey"].Value.ToString(); switch (status)
{
case "Print in Progress":
string erpSoNumber = this.dgMain.Rows[row].Cells["dgMain_ErpSoNumber"].Value.ToString(); //从DB中查找erp_so_number的记录
IEnumerable<FileIndexModel> fileIndexes = _serviceClient.GetFileIndex(erpSoNumber); //如果在FileIndex表中存在pro的记录
if (fileIndexes == null || !fileIndexes.Any()) { break; } FileIndexModel fileIndex = fileIndexes.First(); if (FileStatus.PRINTED != fileIndex.PrintedStatus && FileStatus.PARTIAL_PRINTED != fileIndex.PrintedStatus)
{
e.Value = Properties.Resources.picYellow;
}
else
{
e.Value = Properties.Resources.picGreen;
} break; case "Printed": e.Value = Properties.Resources.picGreen;
break; case "Partial Printed": e.Value = Properties.Resources.picGreen;
break; default: e.Value = Properties.Resources.picYellow;
break;
}
}
} #endregion }
}

勇哥:“......”

炮哥:“很简单,写得很明白,这方法没什么问题吧,会不会搞错了。”

勇哥:“应该不会,通过CLR Profile分析发现,在这个方法中创建了非常多的对象。”

炮哥:“你是说BitMap对象?”

勇哥:“是的。”

炮哥:“噢,明白了,每次访问Properties.Resources.picGreen类似的属性时,都会创建一个新的对象。但其实图标就那么几类,完全可以先保存在内存中,要用时直接引用就行了。”

勇哥:“说得对,让我修改下代码 ,看看情况。”

炮哥:“让我看下你怎么修改的?”

勇哥:“......”

 namespace IPP_PCL.HomeViewUserControl
{
public partial class PrintOrderInformationUserControl : UserControl, IHomePrintOrderInformationView
{
#region Field private readonly PrintCellLiteServiceClient _serviceClient = new PrintCellLiteServiceClient(); Bitmap picGreenBitMap = Properties.Resources.picGreen; Bitmap picYellowBitMap = Properties.Resources.picYellow; #endregion #region Ctor public PrintOrderInformationUserControl()
{
InitializeComponent();
} #endregion #region Event Handler /// <summary>
/// 此事件主要用于图片按钮的显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgMain_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dgMain.Columns[e.ColumnIndex].Name.Equals("dgMain_PrintIcon"))
{
int row = e.RowIndex;
//获取展示图片按钮的单元格
string status = dgMain.Rows[row].Cells["dgMain_statusKey"].Value.ToString(); switch (status)
{
case "Print in Progress": var proDt = dgMain.DataSource as DataTable; if (proDt == null || proDt.Rows.Count == ) { break; } string erpSoNumber = this.dgMain.Rows[row].Cells["dgMain_ErpSoNumber"].Value.ToString(); //从DB中查找erp_so_number的记录
IEnumerable<FileIndexModel> fileIndexes = _serviceClient.GetFileIndex(erpSoNumber); //如果在FileIndex表中存在pro的记录
if (fileIndexes == null || !fileIndexes.Any()) { break; } FileIndexModel fileIndex = fileIndexes.First(); if (FileStatus.PRINTED != fileIndex.PrintedStatus && FileStatus.PARTIAL_PRINTED != fileIndex.PrintedStatus)
{
e.Value = picYellowBitMap;
}
else
{
e.Value = picGreenBitMap;
} break; case "Printed": e.Value = picGreenBitMap;
break; case "Partial Printed": e.Value = picGreenBitMap;
break; default: e.Value = picYellowBitMap;
break;
}
}
} #endregion }
}

炮哥:“再用CLR Profile分析下修改后的内存情况。”

勇哥:“你看,内存直接从9.0M变为425kB。”

炮哥:“哈哈,看来问题已经解决了。”

勇哥:“今天我发现C#也有闭包的概念。”

炮哥:“闭包?什么玩意?”

勇哥:“我是在学习JS的时候发现有闭包这个概念,但是没想到C#也有这个。”

炮哥:“所以说当你视野放开时,你会发现更多的美好。”

勇哥:“不扯了,该下班了。噢,对了,昨晚看了一部电影<美丽人生>,有兴趣的话可以看下,很不错。”

第一次通过CLR Profile解决内存占用过高的问题的更多相关文章

  1. CLR Profile解决内存占用过高

    CLR Profile解决内存占用过高的问题 炮哥:"嘿,哥们,忙啥呢,电脑卡成这逼样." 勇哥:"在用CLR Profile工具分析下FlexiPrint的内存占用情况 ...

  2. PHPExcel解决内存占用过大问题-dw 查找memoryCacheSize把1M改为2048M

    http://blog.sina.com.cn/s/blog_4ec7952d0101fcrd.html PHPExcel解决内存占用过大问题-设置单元格对象缓存 PHPExcel是一个很强大的处理E ...

  3. Spring cloud开发内存占用过高解决方法

    https://blog.csdn.net/wanhuiguizong/article/details/79289986 版权声明:本文为博主原创文章,转载请声明文章来源和原文链接. https:// ...

  4. PHPExcel解决内存占用过大问题-设置单元格对象缓存

    PHPExcel解决内存占用过大问题-设置单元格对象缓存 PHPExcel是一个很强大的处理Excel的PHP开源类,但是很大的一个问题就是它占用内存太大,从1.7.3开始,它支持设置cell的缓存方 ...

  5. [转帖]Linux中buff/cache内存占用过高解决办法

    Linux中buff/cache内存占用过高解决办法 https://www.cnblogs.com/rocky-AGE-24/p/7629500.html /proc/sys/vm/drop_cac ...

  6. 通过修改my.ini配置文件来解决MySQL 5.6 内存占用过高的问题

    打开后台进程发现mysql占用的内存达到400+M. 修改一下my.ini这个配置文件的配置选项是可以限制MySQL5.6内存占用过高这一问题的,具体修改选项如下: performance_schem ...

  7. [2017-08-09]一则使用WinDbg工具调试iis进程调查内存占用过高的案例

    最近遇到一个奇葩内存问题,跟了三四天,把Windbg玩熟了,所以打算分享下. 症状简介 我们团队的DEV开发环境只有一台4核16G的win2012r2. 这台服务器上装了SqlServer.TFS(项 ...

  8. 【转】一则使用WinDbg工具调试iis进程调查内存占用过高的案例

    最近遇到一个奇葩内存问题,跟了三四天,把Windbg玩熟了,所以打算分享下. 症状简介 我们团队的DEV开发环境只有一台4核16G的win2012r2.这台服务器上装了SqlServer.TFS(项目 ...

  9. 一个神奇的bug:OOM?优雅终止线程?系统内存占用较高?

    摘要:该项目是DAYU平台的数据开发(DLF),数据开发中一个重要的功能就是ETL(数据清洗).ETL由源端到目的端,中间的业务逻辑一般由用户自己编写的SQL模板实现,velocity是其中涉及的一种 ...

随机推荐

  1. robotframework+appium,数字键盘输入问题,keycode,press keycode

    需要注意事项 appium自带的输入法应该是无法模拟控制键和基本键的,需要自行使用adb切换成搜狗或者android输入法,然后case完成之后记得切回appium输入法 appium模拟发送基本键命 ...

  2. [SGU223]Little Kings(状压DP)

    随便DP一下 Code #include <cstdio> int sta[150],cnt[150],tp,n,k; long long dp[12][144][150],Ans; in ...

  3. Java设计模式(5)——创建型模式之建造者模式(Builder)

    一.概述 概念 将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示.(与工厂类不同的是它用于创建复合对象) UML图   主要角色 抽象建造者(Builder)——规范建造方法与结果 ...

  4. 北京Uber优步司机奖励政策(12月21日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. LiteOS创建任务的一个BUG

    在任务创建的时候,参数无法传递,第二个参数本来是用来做参数传递的,但是却没用到,很尴尬啊,缺少了这个功能,很多无法写了? osThreadId_t osThreadNew (osThreadFunc_ ...

  6. linux-centos6①

  7. UE4蓝图小记

    http://www.element3ds.com/forum.php?mod=viewthread&tid=76930&page=1&authorid=104414 http ...

  8. flume 整合 kafka

    flume 整合 kafka:   flume:高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统. kafka:分布式的流数据平台.   flume 采集业务日志,发送到kafka   一. ...

  9. 8月leetcode刷题总结

    刷题链接:https://leetcode-cn.com/explore/ 根据leetcode的探索栏目,八月份一直在上面进行刷题.发现算法题真的好难,真-计算机思维. 核心是将现实问题转化为计算机 ...

  10. leetcode-生成括号(回溯算法)

     转载出处:https://blog.csdn.net/yanerhao/article/details/68561290 生成括号     给出 n 代表生成括号的对数,请你写出一个函数,使其能够生 ...