当前位置:网站首页>记录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;
}
边栏推荐
- [binary search] 34 Find the first and last positions of elements in a sorted array
- UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
- Cocos progress bar progresstimer
- Judge the position of the monster in the role under unity3d
- Haut OJ 1221: a tired day
- 被舆论盯上的蔚来,何时再次“起高楼”?
- Magnifying glass effect
- Haut OJ 1316: sister choice buys candy III
- 《动手学深度学习》学习笔记
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
猜你喜欢

UE 虚幻引擎,项目结构

十年不用一次的JVM调用
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
[merge array] 88 merge two ordered arrays

TF-A中的工具介绍
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

Learning notes of "hands on learning in depth"

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

小程序直播+电商,想做新零售电商就用它吧!

Embedded database development programming (V) -- DQL

Merge sort
随机推荐
64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
room数据库的使用
JVM call not used once in ten years
Page countdown
Haut OJ 1350: choice sends candy
[depth first search] 695 Maximum area of the island
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Recherche de mots pour leetcode (solution rétrospective)
Basic knowledge points of dictionary
[to be continued] [UE4 notes] L3 import resources and project migration
Collapse of adjacent vertical outer margins
Fragment addition failed error lookup
嵌入式数据库开发编程(六)——C API
Romance of programmers on Valentine's Day
使用命令符关闭笔记本自带键盘命令
Development error notes
cocos2dx_ Lua particle system
Embedded database development programming (VI) -- C API
Listview pull-down loading function
Es module and commonjs learning notes -- ESM and CJS used in nodejs