当前位置:网站首页>A problem and solution of recording QT memory leakage
A problem and solution of recording QT memory leakage
2022-07-05 05:25:00 【Passing bears~】
brief introduction
The phenomenon :
qt Sometimes used in new Not used after delete
reason :
Qt Automatic recycling depends on the relationship between father and son . Father destroyed it . His children were also destroyed .
Example
#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);
// Use here new There is no need to perform delete, because label The parent class is w, and w Is to create... In the stack , It will be released automatically when the program is closed , So as w Subclass memory is also released .
QLabel *label1 =new QLabel("world");
// This needs to be executed delete label1, Otherwise, memory leakage will occur , because label No parent , So not for label Free memory .
w.show();
a.exec();
delete label1;
label1=NULL;
return 0;
}
边栏推荐
- 被舆论盯上的蔚来,何时再次“起高楼”?
- kubeadm系列-02-kubelet的配置和启动
- Reverse one-way linked list of interview questions
- [interval problem] 435 Non overlapping interval
- Fragment addition failed error lookup
- Bucket sort
- 2022年上半年国家教师资格证考试
- Use of room database
- Under the national teacher qualification certificate in the first half of 2022
- Use of snippets in vscode (code template)
猜你喜欢
To the distance we have been looking for -- film review of "flying house journey"
[转]: OSGI规范 深入浅出
YOLOv5添加注意力机制
十年不用一次的JVM调用
Gbase database helps the development of digital finance in the Bay Area
GBase数据库助力湾区数字金融发展
Web APIs DOM节点
Embedded database development programming (zero)
[to be continued] [UE4 notes] L1 create and configure items
小程序直播+电商,想做新零售电商就用它吧!
随机推荐
Haut OJ 1221: a tired day
Download xftp7 and xshell7 (official website)
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
Improvement of pointnet++
Do a small pressure test with JMeter tool
2022上半年全国教师资格证下
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
Haut OJ 1241: League activities of class XXX
[turn to] MySQL operation practice (I): Keywords & functions
[to be continued] [depth first search] 547 Number of provinces
Magnifying glass effect
[trans]: spécification osgi
Service fusing hystrix
Reverse one-way linked list of interview questions
使用Electron开发桌面应用
[depth first search] 695 Maximum area of the island
sync.Mutex源码解读
TF-A中的工具介绍
win10虚拟机集群优化方案
Embedded database development programming (V) -- DQL