日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > CSharp - Memory leaks problem detection and solution

CSharp - Memory leaks problem detection and solution

來源:程序員人生   發布時間:2015-03-24 08:47:36 閱讀次數:3440次

/* By Dylan SUN*/

Out of memory exception happens when server doesn’t have enough memory to run the application.

This often happens when you are dealing with external resources, such as consuming Interop libraries, treating files, streams, etc.

Memory is a limited resource, it’s easy to be run out of. So, you should be careful when you are working with external resources in your application development.

There are some good memory profilers in the market.
I’ve listed two profilers I’ve used. They are both very easy to use. You can even try them for a limited period.

  1. DotTrace
  2. Ants Memory Profiler

Here are some screenshots of one snapshot in Ants memory profiler.

You could see the memory usage progress with time.
progress

You could easily see the memory usage with Heap generation 1, generation 2, Large object heap, Unused memory allocated to .NET, Unmanaged memories.

這里寫圖片描述

Then you could investigate which instance of class is used, how much times it’s been used, how many memory it has occupied, etc.

這里寫圖片描述

The best practice to consume an external data source is using “using” statement. Everything you get in external services will be disposed.

using (var service = _serviceAdapter.Configure()) { var data = _serviceAdapter.RetrieveData(parameters); }

If you need to use the retrieved data in several places in your application. You can convert it to a DTO object, so the code becomes managed.

DataDto dataDto = new DataDto(); using (var service = _serviceAdapter.Configure()) { var data = _serviceAdapter.RetrieveData(parameters); dtoData = ConvertToDto(data); }

In this way you can use dtoData wherever you like.
After the object’s usage, the data will be collected by GC later.

You can translate the previous code into :

Service service = new Service(); Data data = new Data(); try { service = _serviceAdapter.Configure(); data = _serviceAdapter.RetrieveData(parameters); dtoData = ConvertToDto(data); } finally { service.Dispose(); data.Dispose(); }

If you want to ensure that all exceptions will be caught. You can do something like this:

Service service = new Service(); Data data = new Data(); try { service = _serviceAdapter.Configure(); data = _serviceAdapter.RetrieveData(parameters); dtoData = ConvertToDto(data); } catch(Exception ex) { Logger.LogError(ex.Message + ex.StackTrace); } finally { service.Dispose(); data.Dispose(); }

I hope you find this articles helpful!

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 午夜久久久 | 国产中文字幕一区 | 亚洲午夜视频在线观看 | 国产一区二区三区在线免费观看 | 国产精品美女www | 一区二区三区免费在线观看 | 91玖玖| 亚洲最大福利网站 | 中文字幕123 | 久久不卡 | 日韩成人免费观看 | 久久久久网站 | 男人天堂国产 | 开操网 | 欧美日韩国产在线观看 | 天堂网亚洲 | 亚洲第一天堂无码专区 | 999精品视频在这里 亚洲一级免费观看 | 丁香六月婷婷 | 国产免费高清 | 黄色高清视频 | 午夜视频一区二区三区 | 日韩在线观看中文字幕 | 爱爱视频在线观看 | 日日夜夜综合 | 亚洲综合视频在线 | 日韩电影一区二区三区 | 亚洲精品aaaa | 精品国产一 | 极品视频在线 | 伊人三区| 成人在线视频一区 | 国产精品电影在线观看 | 国产精品免费观看视频 | 成人精品免费视频 | 国产精选久久 | 国产精品高清一区二区三区 | 99久久精约久久久久久清纯 | 嫩草影院地址 | 亚洲成色999久久网站 | 欧美高清视频一区 |