当前位置:网站首页>记录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;
}
边栏推荐
- UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
- Haut OJ 1243: simple mathematical problems
- [to be continued] [depth first search] 547 Number of provinces
- Lua GBK and UTF8 turn to each other
- JVM call not used once in ten years
- The next key of win generates the timestamp file of the current day
- 支持多模多态 GBase 8c数据库持续创新重磅升级
- 【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
- 2022上半年全国教师资格证下
- Download and use of font icons
猜你喜欢
![[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research](/img/17/db8614b177f33ee4f67b7d65a8430f.png)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research

Unity ugui source code graphic
![[to be continued] [depth first search] 547 Number of provinces](/img/c4/b4ee3d936776dafc15ac275d2059cd.jpg)
[to be continued] [depth first search] 547 Number of provinces

Redis has four methods for checking big keys, which are necessary for optimization

嵌入式数据库开发编程(五)——DQL

Magnifying glass effect

Leetcode word search (backtracking method)

Merge sort

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

Recherche de mots pour leetcode (solution rétrospective)
随机推荐
Unity find the coordinates of a point on the circle
Embedded database development programming (zero)
小程序直播+电商,想做新零售电商就用它吧!
Listview pull-down loading function
Cocos progress bar progresstimer
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
[LeetCode] 整数反转【7】
PMP考生,请查收7月PMP考试注意事项
对象的序列化
嵌入式数据库开发编程(零)
Development error notes
Chinese notes of unit particle system particle effect
[binary search] 69 Square root of X
[转]MySQL操作实战(一):关键字 & 函数
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Merge sort
Reverse one-way linked list of interview questions
Generate filled text and pictures
[to be continued] [UE4 notes] L3 import resources and project migration
The present is a gift from heaven -- a film review of the journey of the soul