开发者

Memory leak using QVector

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜