日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

.net 垃圾回收学习[How To: Use CLR Profiler][翻译学习]【2】

發布時間:2023/12/2 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net 垃圾回收学习[How To: Use CLR Profiler][翻译学习]【2】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://msdn.microsoft.com/zh-cn/library/ms979205

注意:內容可能已經過期了。

注意:CLR Profiler最新版本:http://www.microsoft.com/download/en/details.aspx?id=16273

Identifying Common Garbage Collection Issues


可以使用CLR Profiler.exe來識別和隔離GC相關的內存問題,包括內存消耗相關的內容:

  • 過多的分配。 Excessive Allocations
  • 未知的分配。 Unknown Allocations
  • 內存泄漏。 memory leaks.

也包含和GC相關的內容:

  • 過多的收集。 Excessive Collections
  • 長生命周期對象。 long-lived objects
  • 每次GC操作消耗的時間百分比。 percentage of time spent performing garbage collection

注意:For more detailed information about using CLR Profiler to solve common problems related to garbage collection, see "Common Garbage Collection Problems and How They are Reflected In These Views" in CLRProfiler.doc, which is located in the installation folder of CLR Profiler.

Identifying Where Your Application Allocates Memory


當你和內存消耗的問題打交道的時候,最好知道你的應用程序在那里分配內存。

To identify where your application allocates memory, follow these steps:

  • Run CLR Profiler on the sample application.? 在CLR Profiler上運行示例程序。
  • Analyze allocated memory types. 分析分配的內存類型。
  • Determine who is allocating the memory. 確定是誰在分配內存。
  • Evaluate what you can do to reduce the allocations. 評估你你能夠采取的降低分配的措施。
  • Step 1. Run CLR Profiler on the Sample Application
    Step 2. Analyze Allocated Memory Types?
    ???? 在View菜單上,點擊Histogram Allocated Types. 顯示如下圖所示:

    這張圖顯示在Application的生命周期中被分配的對象。在這個示例中,將近2G的對象被分配,大多數都是String. 原因是你使用示例中的字符串的連接方式,.net framework每次都分配一個新的長字符串,并且將舊的字符串復制過來。

    Use the Histogram Allocated Types view to watch for objects that are allocated in the large object heap (those objects larger than 85 KB). You can select specific bar graphs in the left or right pane, and then right-click to see who allocated the memory. This view gives you a high-level view of the objects that are being allocated during the lifetime of your application.

    Step 3. Determine Who is Allocating the Memory


    點擊Allocation Graph,你可以在圖1中字符串區域點擊右鍵,查看 show who allocated, 這個操作顯示了被選定的分配的詳細情況而不是所有的分配情況,如下圖所示:

    在這個示例中,你可以看到幾乎所有的內存都是被String.Contact方法分配的。

    Allocation Graph可以為你提供以下信息:

    • 查看每個方法的分配成本
    • 分析你不期望的分配
    • 查看某個函數是否存在過多的分配
    • 對比完成同樣工作的不同方法

    Step 4. Evaluate What You Can Do to Reduce the Allocations


    現在你知道你的應用程序內存主要消耗在哪里了,可以采取措施降低內存的消耗了。在這個示例中,可以采用StringBuilder而不是String Concatenation.

    轉載于:https://www.cnblogs.com/sunshinefly128/archive/2011/08/28/2156486.html

    總結

    以上是生活随笔為你收集整理的.net 垃圾回收学习[How To: Use CLR Profiler][翻译学习]【2】的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。