当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Embedded database development programming (V) -- DQL
[to be continued] [depth first search] 547 Number of provinces
《动手学深度学习》学习笔记
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
[merge array] 88 merge two ordered arrays
C语言杂谈1
Learning notes of "hands on learning in depth"
Heap sort summary
服务熔断 Hystrix
C language Essay 1
随机推荐
Learning notes of "hands on learning in depth"
UE fantasy engine, project structure
Solon Logging 插件的添加器级别控制和日志器的级别控制
Bucket sort
Haut OJ 1245: large factorial of CDs --- high precision factorial
Embedded database development programming (V) -- DQL
[allocation problem] 135 Distribute candy
Simple HelloWorld color change
[to be continued] [depth first search] 547 Number of provinces
YOLOv5添加注意力機制
Pointnet++的改进
Summary of Haut OJ 2021 freshman week
注解与反射
[speed pointer] 142 circular linked list II
A new micro ORM open source framework
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
National teacher qualification examination in the first half of 2022
Do a small pressure test with JMeter tool
Introduction to tools in TF-A
Add level control and logger level control of Solon logging plug-in