当前位置:网站首页>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
边栏推荐
- .104History
- Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]
- JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
- MATLAB从入门到精通(二)
- 7-21 wrong questions involve knowledge points.
- Closure type of rust (difference between FN, fnmut and fnone)
- Map basemap Library
- Stanford machine learning course summary
- MATLAB小技巧(6)七种滤波方法比较
- Gobang game based on pyGame Library
猜你喜欢
【ACM】376. 摆动序列
JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Quantexa CDI(场景决策智能)Syneo平台介绍
Installation du docker redis
STM32 learning record 0008 - GPIO things 1
.105Location
Auto. JS custom dialog box
Calculation of fishing net road density
Scikit learn sklearn 0.18 official document Chinese version
随机推荐
读取excel,int 数字时间转时间
Docker 安裝 Redis
多功能工具箱微信小程序源码
Multifunctional toolbox wechat applet source code
proxy server
Installation du docker redis
Permission management with binary
【ACM】376. 摆动序列
Robocode Tutorial 4 - robocode's game physics
【ACM】70. climb stairs
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Scikit learn sklearn 0.18 official document Chinese version
Implement a simple function to calculate the sum of all integers between M ~ n (m < n)
Log4j2 cross thread print traceid
Nat commun | current progress and open challenges of applied deep learning in Bioscience
powerdesigner各种字体设置;preview字体设置;sql字体设置
Gson fastjason Jackson of object to JSON difference modifies the field name
Quantexa CDI(场景决策智能)Syneo平台介绍
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)