当前位置:网站首页>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
边栏推荐
- Multifunctional toolbox wechat applet source code
- MATLAB从入门到精通(二)
- 由tcl脚本生成板子对应的vivado工程
- Docker 安装 Redis
- Closure type of rust (difference between FN, fnmut and fnone)
- Selenium + phantom JS crack sliding verification 2
- 硬核解析Promise對象(這七個必會的常用API和七個關鍵問題你都了解嗎?)
- 线上怎么确定期货账户安全的?
- Differences between SSD hard disk SATA interface and m.2 interface (detailed summary)
- Crawl the product data of cicada mother data platform
猜你喜欢

Robocode tutorial 8 - advanced robot
![[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)](/img/74/bb173ca53d62304908ca80d3e96939.png)
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)

re正則錶達式

WIN1 remote "this may be due to credssp encryption Oracle correction" solution

【ACM】376. 摆动序列
![[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader](/img/45/f9e24ae1c619f78aeeb7bcf12d6e5f.png)
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader

logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours
![Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]](/img/5f/a80951777a0473fcaa685cd6a8e5dd.png)
Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]

QT reading and writing XML files (including source code + comments)

Process management command
随机推荐
journal
Log4j2 cross thread print traceid
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
WIN1 remote "this may be due to credssp encryption Oracle correction" solution
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
由tcl脚本生成板子对应的vivado工程
Crawl the product data of cicada mother data platform
QT reading and writing XML files (including source code + comments)
Nodejs安装
Solution to Chinese garbled code after reg file is imported into the registry
Re expression régulière
RC smart pointer in rust
【ACM】376. 摆动序列
Reptile efficiency improvement method
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
消费者灰度实现思路
The difference between deep copy and shallow copy
mysql自动启动设置用Systemctl start mysqld启动
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Jenkspy package installation