开发者

Memory leak using QVector

开发者 https://www.devze.com 2023-04-08 02:13 出处:网络
QVector<cLibraryRecord> Library; ... Library.push_back(cLibraryRecord(ReaderFullName, BookGenre, BookTitle, AuthorsFullName, IssueDate, ReturnDate));
QVector<cLibraryRecord> Library;
...
Library.push_back(cLibraryRecord(ReaderFullName, BookGenre, BookTitle, AuthorsFullName, IssueDate, ReturnDate));
...
Library.remove(i);

QVector::remove() does not clear the memory. How can I clean the memor开发者_高级运维y? Thanks in advance.


QVector.remove() always calls the destructor for the contained object, but the reserved size (returned by QVector::capacity()) doesn't shrink automatically when you remove elements.

You can use QVector::squeeze() to release the unused reserved memory.

But you can also have a memory leak in your class cLibraryRecord.

See Qt documentation for more details: Qt containers growth strategies.

0

精彩评论

暂无评论...
验证码 换一张
取 消