zoukankan      html  css  js  c++  java
  • 认真的程序员最可爱

    记录一段小经历,当我们嗅觉到一段有问题的代码时,仔细研究下会有不错的发现。 

    经验总结:当我们跟IntPtr打交道时一定要小心谨慎,谨防GDI泄漏

     

    Yesterday, I noticed that some image resources in Annotation project are not defined as static, the client directly access by “Properties.Resources…”.

    As far as I know is, in original we have a ‘rule’ that the image resource should defined as static in order to defense GDI leak. (I’m not sure about this, because I could not find out the related mail now.)

     

    So, I test the annotation ribbon, and found there does exist GDI leak problem. If we change the callout shape type or toggle “Keep On Top” check box continuously, the GDI increased shapely, when it reach to 9999, the Application crashed. Please refer to 【...】.

    Jerry has helped me located the key problem, that in AnimatedBusyCursor.cs class, line 66, it create a Cursor by IntPtr, but never destroy it. Thanks, Jerry, it’s a amazing found.

     

    I have downloaded his code and tested, it works well. All the increased GDI object can be decrease now. So I’m not sure if we still need defined the image resource as static. In 【...】, I does defined the image resource as static. Please help me to review it. If you don’t mind, I want to check in those code. Any problem, please let me know.

     

    (It is strange to me that why it is ok now we directly use the image resource. I guess it may related to the some Contextual Ribbon changes. In early time, the contextual ribbon for annotation can have several copies at the same time, it will created a copy when show annotation’s contextual ribbon, and never released.  So if we don’t defined the image as static, it may reference more than once by the ribbon control, so the GDI increased. Since, currently this problem has been solved, there is only one copy contextual ribbon, so maybe directly access the image is ok. I’m not sure, just guessingJ)

  • 相关阅读:
    [Java] Hibernate
    python基础(十三):函数(一)公共操作
    python基础(十二):数据结构(五)集合
    python基础(十二):数据结构(四)字典
    python基础(十一):数据结构(三)元组
    python基础(十):数据结构(二)列表
    python基础(八):流程控制(五)循环
    python基础(七):流程控制(一)if
    python基础(六):运算符
    python基础(五):转换数据类型
  • 原文地址:https://www.cnblogs.com/anders06/p/1804835.html
Copyright © 2011-2022 走看看