GDI泄露检测

GDI资源泄露检测与管理工具深入解析 GDI(Graphical Device Interface)对象,即图形设备接口对象,是Windows操作系统中用于提供设备无关的图形输出的核心组件。GDI对象使得应用程序能够不关心物理输出设备的具体细节,通过统一的API进行图形绘制。这些对象包括但不限于画笔(Pen)、画刷(Brush)、字体(Font)、位图(Bitmap)、区域(Region)等,每种对象在图形输出过程中担当不同角色。GDI对象在创建后必须在使用完毕后销毁,以释放系统资源。如果GDI对象未能正确销毁,就会导致资源泄露。 阅读详情

前一段在一个仿QQ的IM通讯工具中加入屏幕截图以及截图编辑功能,但是测试中发现当连续进行几十次截图后,系统会出现白屏,开始以为和win7经常闪白有关,屏幕截图截取到闪白的瞬间导致白屏,后来发现是GDI内存不足,申请不到GDI内存贴图失败所致。于是找了GDI泄露的工具,对程序进行GDI内存检测,下面就介绍两款GDI泄露检测工具的用法以及GDI编程的一些注意事项。

第一款:GDIndicator 支持win7+xp 下载地址

1、启动待检测的程序和GDIndicator,启动顺序没有要求,之后F5刷新,就能看到系统中所有进程,和使用的资源数

找到想要查看的进程,这里我们的程序是 TPCommonControlTest,双击进入没有释放的GDI对象列表

在左边list控件中单击GDI对象,即可查看,对于可用bitmap对象,还可以看缩略图。

2、进行可能引起泄露的操作,并复原,对本程序来说,就是打开聊天窗口,屏幕截图,并关闭聊天窗口。

     如果没有GDI泄露,在进行上述操作后,GDI对象应该没有改变,如果改变了,根据差值,查找泄露的GDI对象。

3、下图是进行操作后,的GDI对象使用情况,根据差值,重点分析有哪些泄露


根据对比发现,新增了1个bitmap2个dc对象,然后双击TPCommonControlTest进程,结合代码分析,看哪些地方使用DC了,以及是否释放。这个工具定位不是很精确,不能给出调用堆栈等,只能由程序员根据新增对象分析、查找。

第二款工具,GdiLeakDetector,支持xp,win7支持不是很好,可以精确定位GDI泄露位置 下载地址:

使用方法:

1、打开GdiLeakDetector,找到要检测的程序,并点击运行程序按钮


2、进行可能出现泄露的操作,并退出程序,并依次点击左边的GDI泄露列表,看哪个是可以修改的


如上图所示,很容易的找到,在copyclipbrd中有dc泄露,去函数中查看,发现dc是通过CreateCompatibleDC函数创建的,但是释放时用了releaseDC,这是不对的,对于CreateCompatibleDC申请的DC,应该用deletedc释放,而getDC取得的DC资源,用releaseDC释放,不对应的话就会造成GDI泄露。

附:GDI使用的几个注意点:

http://blog.csdn.net/bobob/archive/2005/12/29/565188.aspx

1、Create出来的GDI对象,要用Deleteobject释放, create出来的DC,要用DeleteDc释放,getDC得出的DC,用ReleaseDc释放。

2、先create后delete, create1,create2, delete2,delete1的顺序。

3、画图步骤

a 创建一个内存兼容dc(CreateCompatibleDC)
b.创建一个内存兼容bitmap(CreateCompatibleBitmap)
c.关联创建的内存兼容dc和bitmap(SelectObject)
d.画图
e.BitBlt到目的dc上
f.断开内存兼容dc和bitmap关联(SelectObject)
g.销毁内存兼容bitmap
h.销毁内存兼容dc

GDI对象泄露检测工具GdiLeakDetector实战解析 简单来说,GDI(Graphics Device Interface)是Windows操作系统提供的核心图形子系统,负责所有屏幕绘制、打印机输出、图像处理等视觉呈现任务。你在界面上看到的每一个按钮边框、每一段文字、每一幅图标,背后都是GDI在默默工作。当你调用。 阅读详情

相关推荐

智能驾驶小白必看:MEB低速紧急制动系统的工作原理与传感器配置详解

本文深入解析了MEB低速紧急制动系统的工作原理与传感器配置。该系统作为智能驾驶的关键安全冗余,专为应对停车场、拥堵路段等复杂低速场景设计。文章详细拆解了其如何通过超声波雷达、环视摄像头等传感器融合感知环境,并基于碰撞时间(TTC)等模型进行风险评估与分级制动,最终实现主动防碰撞,是智能驾驶技术实用化的重要体现。

c2d3e4f的博客 1137

内存泄漏之GDI泄露检测

对开发中常见的内存泄露,GDI泄露进行检测 一、GDI泄露检测方法: 在软件测试阶段,可以通过procexp.exe 工具,或是通过任务管理器中选择GDI对象来查看软件GDI的对象是使用情况。 注意点:Create出来的GDI对象,都要用DeleteObject来释放;Create出来的DC,都要用DeleteDC来释放,GetDC得出的DC,要用ReleaseDC来释放。   以下

精彩的艺术 2013

HFSS15 win10_64位破解

HFSS15 win10_64位破解 找到的别人的软件,但在首次安装时失败了,并不能patched。寻找了几种方法,已成功安装。在此写下安装经验,供大家参考。 软件安装包以及破解软件: 链接:https://pan.baidu.com/s/1MMjV_31maU5QD6fmI4zfIA 提取码:yj4q 在安装之前,建议关闭杀毒软件。 Step1:进入HFSS150Win64安装包,点击au...

玉笙寒 4万+

对开发中常见的内存泄露,GDI泄露进行检测

对开发中常见的内存泄露,GDI泄露进行检测一、GDI泄露检测方法:在软件测试阶段,可以通过procexp.exe 工具,或是通过任务管理器中选择GDI对象来查看软件GDI的对象是使用情况。注意点:Create出来的GDI对象,都要用DeleteObject来释放;Create出来

lin_angle的专栏 6966

SIMPLIS实战:从零构建理想BUCK电路,精准计算与POP稳态分析

本文详细介绍了如何使用SIMPLIS软件从零开始构建并仿真一个理想的BUCK降压电路。通过设定关键参数、计算理想器件值,并搭建仿真模型,文章重点演示了暂态仿真以观察电路上电过程,并深入讲解了高效的POP(周期性工作点)稳态分析技术,帮助工程师快速验证设计、评估稳态性能,从而加速电源设计迭代。

weixin_29165465的博客 400

滤波算法实现大全——基于匀速直线运动模型的kalman滤波算法

滤波算法实现大全——基于匀速直线运动模型的kalman滤波算法

jane0819的博客 528

GDI+ 和MFC内存泄露检测

  原文地址:http://www.codeproject.com/KB/GDI-plus/gdiplush.aspx绪论当我开始使用VC++6.0进行GDI+和MFC编程后,我遇到了一些麻烦的问题:不移除DEBUG_NEW 宏就不能编译有MFC的GDI代码不少许修改代码就不能编译有STL的GDI+代码不能探测到内存泄露以下是解决方案怎样使用

Gary's Blog --- A C++ programmer 4017

14、方法论 - 自顶向下与自底向上的结合

本文探讨了如何将自顶向下的规范驱动方法与自底向上的组件构建方法相结合,以形成更加全面的编程理论。通过引入代数法则,简化逻辑关系、提高代码可读性并支持形式化验证,结合实际案例(如智能家居控制系统)展示了如何在设计和实现阶段确保系统的正确性和可靠性。文章还讨论了工具支持的重要性,并提出了未来发展的方向。

lstm7chronicler的博客 177

分享一个检测GDI泄露源码定位的代码

源码地址:https://github.com/henly2/pink 将apihook文件夹复制至工程目录,把HPP添加至工程,在初始化的地方,比如CMainFrame::OnCreate或者CxDialog::OnInitDialog或者WinMain这些地方初始化,使用前using namespace apihook;声明一下 开启检测: // 启动堆栈记录 apihook::S...

Koma的主页 1481

【AIZ智能体】Codex 全能AI助手从部署到使用实战操作详解

Codex 全能AI助手从部署到使用实战操作详解

congge 2997

Qt/C++ 音视频开发 - FFmpeg 安卓版

通过将 FFmpeg 集成到 Qt/C++ 项目中,我们可以实现强大且灵活的音视频处理功能。本文介绍了在安卓平台上使用 FFmpeg 的基本步骤,包括初始化、解码、处理和编码等。实际应用代码示例展示了如何在安卓设备上播放视频。

走向CTO的路上... 1196

工作学习笔记——GDI泄露检测利器

用.Net写的地图编辑器,最近在一个长时间使用的策划手里频繁挂掉。定位到原因应该是GDI泄露。但在几千行代码里手工寻找泄漏点实在是有些困难,直到在网上找到了这个检测GDI泄露的工具GDILeaks。它的强大之处,在于可以将程序里当前占用的gdi位图、dc用图形格式显示出来,这样,泄露点基本上就直接展示在你眼前了。 另外,关于泄露为什么会发生,我还有些疑问。经检查,泄漏点是这样的C

wtyqm的专栏 3234

Android面试必考问题:Android性能优化最全面试题及参考答案(8万字长文)

Android 中的 OOM(Out Of Memory,内存溢出)异常是指应用程序在运行过程中,由于申请的内存空间超过了系统所能提供的最大内存限制而导致的错误。在 Android 中,内存泄漏是指应用中的某些对象在不再被使用后,仍然被其他对象持有引用,导致这些对象无法被垃圾回收器回收,从而占用内存空间,随着时间的推移可能会导致应用内存不足,甚至崩溃。在一次开发 Android 应用的过程中,我发现应用在长时间运行后会出现内存占用过高的情况,导致应用变得卡顿,甚至可能会被系统强制关闭。

大模型大数据攻城狮的专栏 2547

VC++检测和解决GDI泄漏问题

GDI对象是Windows系统中执行绘图操作中要到的,常见的GDI对象有Bitmap位图对象、Brush画刷对象、Pen笔对象、Font字体对象、Region区域对象、DC对象,通过操作这些对象就可以完成绘图操作。

m0_60352504的博客 1095

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 对开发中常见的内存泄露,GDI泄露进行检测
下一篇: Using SetWindowRgn
double2li
博客等级 码龄18年 804粉丝 4571原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值