当前位置:网站首页>记录QT内存泄漏的一种问题和解决方案
记录QT内存泄漏的一种问题和解决方案
2022-07-05 05:17:00 【路过的小熊~】
简介
现象:
qt中有时候使用new后并没有使用delete
原因:
Qt 自动回收是靠父子关系。父亲销毁了。他的孩子也销毁。
示例
#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QLabel *label =new QLabel("hello",&w);
//这里使用new之后不需要执行delete,因为label的父类是w,而w是在栈中创建,在程序关闭的时候会自动释放,所以作为w的子类内存也被释放。
QLabel *label1 =new QLabel("world");
//这个是需要执行delete label1,否则会造成内存泄漏,因为label没有父类,所以不会为label释放内存.
w.show();
a.exec();
delete label1;
label1=NULL;
return 0;
}
边栏推荐
- 十年不用一次的JVM调用
- Collapse of adjacent vertical outer margins
- Haut OJ 1218: maximum continuous sub segment sum
- Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
- [转]MySQL操作实战(一):关键字 & 函数
- Yolov5 ajouter un mécanisme d'attention
- Pointnet++的改进
- room数据库的使用
- 2022/7/2做题总结
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
猜你喜欢
随机推荐
[轉]: OSGI規範 深入淺出
The next key of win generates the timestamp file of the current day
[turn]: Apache Felix framework configuration properties
Merge sort
cocos2dx_ Lua particle system
Unity find the coordinates of a point on the circle
2022上半年全国教师资格证下
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
Es module and commonjs learning notes -- ESM and CJS used in nodejs
[LeetCode] 整数反转【7】
Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
Judge the position of the monster in the role under unity3d
Basic knowledge points
GBase数据库助力湾区数字金融发展
cocos2dx_ Lua card flip
Transport connection management of TCP
Vs2015 secret key
Page countdown
cocos_ Lua listview loads too much data
[binary search] 69 Square root of X
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)


![To be continued] [UE4 notes] L4 object editing](/img/0f/cfe788f07423222f9eed90f4cece7d.jpg)





