当前位置:网站首页>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
边栏推荐
- String function in MySQL
- Mysql database backup command -- mysqldump
- Install pyshp Library
- Docker installation MySQL
- JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
- Docker 安装 Redis
- 7-21 wrong questions involve knowledge points.
- Log4j2 cross thread print traceid
- 串口调试工具cutecom和minicom
- Reptile efficiency improvement method
猜你喜欢
Installation du docker redis
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
C medium? This form of
多功能工具箱微信小程序源码
JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
Deep learning classic network analysis and target detection (I): r-cnn
QT reading and writing XML files (including source code + comments)
Robocode Tutorial 4 - robocode's game physics
【ACM】509. 斐波那契数(dp五部曲)
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
随机推荐
Secure credit
STM32 learning record 0008 - GPIO things 1
re正則錶達式
函数递归以及趣味问题的解决
What are the relationships and differences between threads and processes
Arcpy adds fields and loop assignments to vector data
Cutting permission of logrotate file
Correct opening method of option
【ACM】509. 斐波那契数(dp五部曲)
Crawl the product data of Xiaomi Youpin app
Docker 安装 Redis
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
Multi thread crawling Marco Polo network supplier data
Svn simple operation command
SSD硬盘SATA接口和M.2接口区别(详细)总结
Pyppeter crawler
Gson fastjason Jackson of object to JSON difference modifies the field name
Qt读写XML文件(含源码+注释)
ArcGIS table to excel exceeds the upper limit, conversion failed
proxy server