当前位置:网站首页>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
边栏推荐
- proxy server
- xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
- Jenkspy package installation
- Permission management with binary
- Scikit learn sklearn 0.18 official document Chinese version
- From source code to executable file
- Feign requests the log to be printed uniformly
- Gson fastjason Jackson of object to JSON difference modifies the field name
- Re regular expression
- Robocode tutorial 7 - Radar locking
猜你喜欢

Dynamically add default fusing rules to feign client based on sentinel + Nacos

Docker 安裝 Redis

Robocode tutorial 3 - Robo machine analysis

.105Location

Resolves the interface method that allows annotation requests to be written in postman

Data stream encryption and decryption of C
![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]

Nodejs安装

Docker installation MySQL
![[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)](/img/ae/cbfc01fbcc816915b1794a9d70247a.png)
[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
随机推荐
【ACM】509. 斐波那契数(dp五部曲)
re正则表达式
Secure credit
Pointers in rust: box, RC, cell, refcell
Log4j2 cross thread print traceid
Auto. JS custom dialog box
函数递归以及趣味问题的解决
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Climbing watermelon video URL
Classes and objects
String function in MySQL
Gson fastjason Jackson of object to JSON difference modifies the field name
Reptile efficiency improvement method
Generate verification code
C language to achieve 2048 small game direction merging logic
C language input and output (printf and scanf functions, putchar and getchar functions)
RC smart pointer in rust
Resolves the interface method that allows annotation requests to be written in postman
Docker 安装 Redis
Install pyshp Library