当前位置:网站首页>QT notes on qmap container freeing memory
QT notes on qmap container freeing memory
2022-04-23 18:15:00 【Talent、me】
in the light of QMap、QVector Wait for container memory release problem , For beginners , It's really easy to ignore .
The reason I noticed this problem was when I first used... In my project QMap<xx,xxx> The container can store data normally , But when you need to QMap After the content of is cleared , Insert again and there appears Segment error (segment fault) problem .
QMap<QString,Struct node> test;
/************* . . . A series of insertion actions are carried out in the middle ************/
test.clear();
QMap The built-in clear() Emptying the interface has a drawback , Although you can empty QMap Data in , But the memory space is not empty , It will not be cleared until the end of the program , Now , If you keep emptying the insert , It will lead to the continuous increase of memory .
terms of settlement
Some people say they use the Internet Qt Built in function interface qDeleteAll () To clear .
But I found that this seems to be only for the container with value Value with pointer , Can be used qDeleteAll() To clear memory .
// Tolerable
QMap<int,Struct node*> a;
qDeleteAll(a);
// No good , Will report a mistake
QMap<int,Struct node> a;
qDeleteAll(a);
The method I use swap function
QMap<int,Struct node> test;
QMap<int,Struct node>().swap(test);
// If used swap() function , Then you don't have to use clear() Function
版权声明
本文为[Talent、me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610471579.html
边栏推荐
- Interpretation and compilation of JVM
- The difference between deep copy and shallow copy
- Multifunctional toolbox wechat applet source code
- Climbing watermelon video URL
- 【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
- Rust: how to implement a thread pool?
- Installation du docker redis
- mysql自动启动设置用Systemctl start mysqld启动
- [UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
- Solving the problem of displaying too many unique values in ArcGIS partition statistics failed
猜你喜欢
![Yolov4 pruning [with code]](/img/09/ea4376d52edb7e419ace2cb1e0356b.gif)
Yolov4 pruning [with code]

Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)

解决允许在postman中写入注释请求接口方法

mysql自动启动设置用Systemctl start mysqld启动

PowerDesigner various font settings; Preview font setting; SQL font settings

positioner

【ACM】509. 斐波那契数(dp五部曲)

C medium? This form of

Closure type of rust (difference between FN, fnmut and fnone)

How to install jsonpath package
随机推荐
Mode of interprocess communication
Robocode tutorial 7 - Radar locking
Quantexa CDI(场景决策智能)Syneo平台介绍
Installation du docker redis
Serial port debugging tools cutecom and minicom
powerdesigner各种字体设置;preview字体设置;sql字体设置
串口调试工具cutecom和minicom
Crawl the product data of Xiaomi Youpin app
Random number generation of C #
MATLAB小技巧(6)七种滤波方法比较
Flash operates on multiple databases
word frequency count
Software test summary
Crawler for querying nicknames and avatars based on qqwebapi
Generate verification code
Map basemap Library
Docker 安裝 Redis
What are the relationships and differences between threads and processes
Rust: how to match a string?
WIN1 remote "this may be due to credssp encryption Oracle correction" solution