当前位置:网站首页>记录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;
}
边栏推荐
- Chinese notes of unit particle system particle effect
- [turn to] MySQL operation practice (I): Keywords & functions
- [leetcode] integer inversion [7]
- Cocos progress bar progresstimer
- 64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
- 质量体系建设之路的分分合合
- cocos2dx_ Lua particle system
- Bubble sort summary
- Haut OJ 1243: simple mathematical problems
- LeetCode之單詞搜索(回溯法求解)
猜你喜欢
[turn to] MySQL operation practice (III): table connection
Heap sort summary
[turn]: OSGi specification in simple terms
[speed pointer] 142 circular linked list II
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
[merge array] 88 merge two ordered arrays
Research on the value of background repeat of background tiling
Web APIs DOM节点
对象的序列化
Data is stored in the form of table
随机推荐
Data is stored in the form of table
django连接数据库报错,这是什么原因
Pause and resume of cocos2dx Lua scenario
2022年上半年国家教师资格证考试
Do a small pressure test with JMeter tool
Solon Logging 插件的添加器级别控制和日志器的级别控制
远程升级怕截胡?详解FOTA安全升级
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
小程序直播+电商,想做新零售电商就用它吧!
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Unity intelligent NPC production -- pre judgment walking (method 1)
What is the agile proportion of PMP Exam? Dispel doubts
Heap sort summary
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
小程序直播+電商,想做新零售電商就用它吧!
xftp7与xshell7下载(官网)
Programmers' experience of delivering takeout
嵌入式数据库开发编程(六)——C API
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory