当前位置:网站首页>记录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;
}
边栏推荐
- Haut OJ 1218: maximum continuous sub segment sum
- C language Essay 1
- Research on the value of background repeat of background tiling
- TF-A中的工具介绍
- Es module and commonjs learning notes
- Solon Auth 认证框架使用演示(更简单的认证框架)
- Double pointer Foundation
- 2022上半年全国教师资格证下
- [merge array] 88 merge two ordered arrays
- Magnifying glass effect
猜你喜欢
![[to be continued] [UE4 notes] L2 interface introduction](/img/0f/268c852b691bd7459785537f201a41.jpg)
[to be continued] [UE4 notes] L2 interface introduction

2022/7/2 question summary

UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存

Django reports an error when connecting to the database. What is the reason

Reverse one-way linked list of interview questions

Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!

一个新的微型ORM开源框架

YOLOv5添加注意力機制

Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory

Optimization scheme of win10 virtual machine cluster
随机推荐
十年不用一次的JVM调用
Haut OJ 1243: simple mathematical problems
Do a small pressure test with JMeter tool
Solon Logging 插件的添加器级别控制和日志器的级别控制
Leetcode word search (backtracking method)
Time format conversion
Es module and commonjs learning notes -- ESM and CJS used in nodejs
Unity intelligent NPC production -- pre judgment walking (method 1)
YOLOv5添加注意力机制
2022年上半年国家教师资格证考试
Programmers' experience of delivering takeout
Unity writes timetables (without UI)
Kali 2018 full image download
[allocation problem] 455 Distribute cookies
Embedded database development programming (VI) -- C API
Listview pull-down loading function
质量体系建设之路的分分合合
Haut OJ 1350: choice sends candy
[depth first search] 695 Maximum area of the island
Haut OJ 1357: lunch question (I) -- high precision multiplication