惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
量子位
GbyAI
GbyAI
腾讯CDC
T
Tailwind CSS Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
Docker
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
Jina AI
Jina AI
IT之家
IT之家
Y
Y Combinator Blog

博客园 - Anders06

A memory leak issue with WPF Command Binding 我也谈面试 附赠一份题目 败给了IEqualityComparer 标注随测量物体旋转问题 How to detect memory leak issue 图纸中角度标注算法 Clean Code反案例:什么是不好的API 避免陷阱,重写Equals方法您需要注意的其中2个原则 What’s the problems with the following code 对象池 关于设计和设计文档的2个补充 SelectMany ConverAll & Exists SOS:利用WPF RichTextBox 提取RTF, 莫名丢掉了Underline样式信息 想探讨两个关于设计文档问题 Don‘t Cry for Me, Argentina 拒绝高姿态 Please avoid implement C# Destruction SOS: How to popup a HwndSource on topmost
认真的程序员最可爱
Anders06 · 2010-08-20 · via 博客园 - Anders06

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

经验总结:当我们跟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)