简体   繁体   English

Qt内存使用检查

[英]Qt memory usage check

I am working on legacy application written in Qt 4.8 (C++).我正在研究用 Qt 4.8 (C++) 编写的遗留应用程序。 After I've made my changes I performed some stress tests.在我做出改变之后,我进行了一些压力测试。 I am worried about their results.我很担心他们的结果。 These are my findings:这些是我的发现:

  • Without stress tests RssAnon parameter (I'm working on Linux) increase on time没有压力测试 RssAnon 参数(我在 Linux 上工作)按时增加
  • With stress tests RssAnon increases more rapidly (between 10:05 and 10:20)通过压力测试,RssAnon 增加得更快(在 10:05 和 10:20 之间)

RssAnon 统计信息(来自 /proc/*/status)

I put much effort to avoid dynamic memory use, however I know, that behind the scene Qt use it a lot.我付出了很多努力来避免动态内存使用,但是我知道,在幕后 Qt 经常使用它。 I suspect that calling signal/slot mechanism cause this rapid increase.我怀疑调用信号/插槽机制会导致这种快速增加。 During the tests I pass reference to static object between threads and put it in QAbstractTableModel, based on C-arrays.在测试期间,我在线程之间传递对静态对象的引用,并将其放入基于 C 数组的 QAbstractTableModel 中。 Of course I call begin/endInsert/RemoveRows on every change.当然,我会在每次更改时调用 begin/endInsert/RemoveRows。

My question is, is there any more reliable way to check if there is no long term memory problem?我的问题是,有没有更可靠的方法来检查是否没有长期记忆问题? I used valgrind, but it doesn't show problems with tested code.我使用了 valgrind,但它没有显示测试代码的问题。 Beside that it might not be right tool - everything might be freed on exit, but I want to avoid constant memory increase on runtime.除此之外,它可能不是正确的工具 - 退出时可能会释放所有内容,但我想避免运行时内存不断增加。 Maybe I should check other parameter from procfs?也许我应该检查 procfs 的其他参数?

In the meantime I used massif to monitor the memory usage - this is the right tool.与此同时,我使用massif来监控内存使用情况——这是正确的工具。 I found out that begin/endInsert/RemoveRows methods cause this huge memory consumption in this places:我发现 begin/endInsert/RemoveRows 方法会在这些地方造成巨大的内存消耗:

  • QAccessible::queryAccessibleInterace QAccessible::queryAccessibleInterace
  • QHashData::allocateNode QHashData::allocateNode

Regarding the question, the answer is - Massif - and to view results Massif-visualizer .关于这个问题,答案是 - Massif - 并查看结果Massif-visualizer

To remove this "leak" i had to remove beginInsertRows functions.为了消除这个“泄漏”,我必须删除 beginInsertRows 函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM