当前位置:网站首页>记录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;
}
边栏推荐
- 小程序直播+電商,想做新零售電商就用它吧!
- [merge array] 88 merge two ordered arrays
- Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
- win10虚拟机集群优化方案
- 使用命令符关闭笔记本自带键盘命令
- Download xftp7 and xshell7 (official website)
- Time format conversion
- 一个新的微型ORM开源框架
- Haut OJ 1347: addition of choice -- high progress addition
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
猜你喜欢

Generate filled text and pictures

Leetcode word search (backtracking method)

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

十年不用一次的JVM调用

Shell Sort

Merge sort

Optimization scheme of win10 virtual machine cluster

Unity find the coordinates of a point on the circle

TF-A中的工具介绍

UE fantasy engine, project structure
随机推荐
Es module and commonjs learning notes -- ESM and CJS used in nodejs
C # perspective following
Use of snippets in vscode (code template)
[转]: OSGI规范 深入浅出
Pause and resume of cocos2dx Lua scenario
[转]MySQL操作实战(三):表联结
Binary search basis
UE 虚幻引擎,项目结构
Unity intelligent NPC production -- pre judgment walking (method 1)
嵌入式数据库开发编程(零)
Kali 2018 full image download
Haut OJ 1352: string of choice
2022 / 7 / 1 Résumé de l'étude
Haut OJ 1243: simple mathematical problems
Under the national teacher qualification certificate in the first half of 2022
Data is stored in the form of table
Basic knowledge points of dictionary
Merge sort
Animation
Chinese notes of unit particle system particle effect