MFC C ++中的内存泄漏问题 [英] Memory leak problem in MFC C++

查看:114
本文介绍了MFC C ++中的内存泄漏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,在我的MFC C ++程序中,我的编译器检测到内存泄漏.我使用 CDC * pDC; CBitmap *位图; 在我的头文件中,然后在OnInitDialog()中,我使用: pDC = new CDC;和Bitmap = new CBitmap; .我的编译器将这些检测为内存泄漏.可能是什么问题?预先感谢!

Hello, in my MFC C++ program my compiler detected memory leaks. I use CDC* pDC; and CBitmap* Bitmap; in my header file and then in OnInitDialog() i use: pDC = new CDC; and Bitmap = new CBitmap;. My compiler detected these as a memory leak. What might be the problem? Thanks in advance!

推荐答案

那是正确的.编辑您的帖子以添加详细信息,不要对自己发布虚假答案.
That is correct. Edit your post to add detail, don''t post fake answers to yourself.


问题很明显.您永远不会删除它们.如果在整个程序中都使用了它们,并且始终可见此对话框,那么这并不是真正的问题,但是您仍然应该练习清除析构函数中的所有成员变量.
THe problem is obvious. You never delete them. If they are used throughout the program, and this dialog is always visible, then it''s not really a problem, but you should still get in the practice of cleaning up all member variables in your destructor.


您正在使用
pDC =新的CDC;和位图=新的CBitmap;

使用关键字删除"释放它们.
you are using
pDC = new CDC; and Bitmap = new CBitmap;

use keyword "delete" to free them.


这篇关于MFC C ++中的内存泄漏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆