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.
精彩评论