使用 QVector 的内存泄漏
QVector<cLibraryRecord> Library;
...
Library.push_back(cLibraryRecord(ReaderFullName, BookGenre, BookTitle, AuthorsFullName, IssueDate, ReturnDate));
...
Library.remove(i);
QVector::remove() 不会清除内存。如何清理内存? 提前致谢。
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 memory?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QVector.remove()
始终调用所包含对象的析构函数,但在删除时保留的大小(由QVector::capacity()
返回)不会自动缩小元素。您可以使用
QVector::squeeze()
来释放未使用的保留内存。但是您的类
cLibraryRecord
中也可能存在内存泄漏。有关更多详细信息,请参阅 Qt 文档:Qt 容器增长策略。
QVector.remove()
always calls the destructor for the contained object, but the reserved size (returned byQVector::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.