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)

  • 相关阅读:
    11 Vue3 UI Framework Card 组件
    12 Vue3 UI Framework 打包发布
    15 Vue3 UI Framework 完工部署
    【译】使用 Visual Studio 调试外部源代码
    IntelliJ JSP 格式化问题
    JSP 学习笔记 | 五、MVC模式和三层架构 & JSP 案例实战
    JSP使用MySQL数据库报错java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    通过Navicate for MySQL导入SQL文件
    MAVEN 配置和基本使用
    JSP 学习笔记 | 二、JSP 脚本 & 案例实现 & 缺点分析
  • 原文地址:https://www.cnblogs.com/anders06/p/1804835.html
Copyright © 2011-2022 走看看