1. <small id='5kwBL'></small><noframes id='5kwBL'>

      <tfoot id='5kwBL'></tfoot>

      <i id='5kwBL'><tr id='5kwBL'><dt id='5kwBL'><q id='5kwBL'><span id='5kwBL'><b id='5kwBL'><form id='5kwBL'><ins id='5kwBL'></ins><ul id='5kwBL'></ul><sub id='5kwBL'></sub></form><legend id='5kwBL'></legend><bdo id='5kwBL'><pre id='5kwBL'><center id='5kwBL'></center></pre></bdo></b><th id='5kwBL'></th></span></q></dt></tr></i><div id='5kwBL'><tfoot id='5kwBL'></tfoot><dl id='5kwBL'><fieldset id='5kwBL'></fieldset></dl></div>
      • <bdo id='5kwBL'></bdo><ul id='5kwBL'></ul>

      1. <legend id='5kwBL'><style id='5kwBL'><dir id='5kwBL'><q id='5kwBL'></q></dir></style></legend>
      2. 在 Qt5.3(mingw32) 中删除 QQuickView 的内存管理问题

        Memory management issue with deleting QQuickView in Qt5.3(mingw32)(在 Qt5.3(mingw32) 中删除 QQuickView 的内存管理问题)

          <i id='ryZyr'><tr id='ryZyr'><dt id='ryZyr'><q id='ryZyr'><span id='ryZyr'><b id='ryZyr'><form id='ryZyr'><ins id='ryZyr'></ins><ul id='ryZyr'></ul><sub id='ryZyr'></sub></form><legend id='ryZyr'></legend><bdo id='ryZyr'><pre id='ryZyr'><center id='ryZyr'></center></pre></bdo></b><th id='ryZyr'></th></span></q></dt></tr></i><div id='ryZyr'><tfoot id='ryZyr'></tfoot><dl id='ryZyr'><fieldset id='ryZyr'></fieldset></dl></div>

            <bdo id='ryZyr'></bdo><ul id='ryZyr'></ul>

            <legend id='ryZyr'><style id='ryZyr'><dir id='ryZyr'><q id='ryZyr'></q></dir></style></legend>
            1. <tfoot id='ryZyr'></tfoot>
            2. <small id='ryZyr'></small><noframes id='ryZyr'>

                  <tbody id='ryZyr'></tbody>
                  本文介绍了在 Qt5.3(mingw32) 中删除 QQuickView 的内存管理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们正在使用 Qt/Qml 开发应用程序(Qml 嵌入在 QWidget 中).删除包含 QQuickView(嵌入式)的 QWidget 时,分配的内存不会完全释放.

                  We are developing an application with Qt/Qml (Qml is embedded in the QWidget). When deleting a QWidget that contains a QQuickView (embedded), the allocated memory won't be freed entirely.

                  通过向应用程序添加 QWidget,将分配大约 30MB 的内存,但是当小部件删除时,只会释放大约 20MB 的内存.

                  By adding a QWidget to application, about 30MB of memory will be allocated but when the widget deletes, only about 20MB of memory will be freed.

                  在QWidget的析构函数中,我已经删除了QQuickView实例,没有其他大对象.

                  In the destructor of QWidget, I have deleted the QQuickView instance and there are no other big objects.

                  另外,我很确定 QQuickView 没有正确释放内存.

                  Also, I am pretty sure that the QQuickView doesn't release memory properly.

                  如何释放 QQuickView 分配的全部内存?

                  How can I free entire memory allocated by QQuickView?

                  注意:代码真的很大(160000行),所以我不能放示例代码.

                  NOTE: The code is really big (160000 Lines), therefore I can't put sample code.

                  提前致谢...

                  推荐答案

                  我已经写了一个快速测试来确定在创建和删除 QQUickWidget 时是否存在实际泄漏:

                  I've written a quick test to determine if there is an actual leak in the creation and deletion of a QQUickWidget:

                  class Widget : public QWidget {
                      Q_OBJECT
                  public:
                      Widget(QWidget *parent = 0) : QWidget(parent) {
                          widget = 0;
                          count = 0;
                          resize(200, 200);
                          layout = new QVBoxLayout(this);
                          setLayout(layout);
                          QTimer * t = new QTimer(this);
                          t->setInterval(200);
                          t->setSingleShot(false);
                          t->start();
                          connect (t, SIGNAL(timeout()), this, SLOT(toggleQuickView()));
                      }
                  
                  public slots:
                      void toggleQuickView() {
                          if (!widget) {
                              widget = new QQuickWidget;
                              widget->setSource(QUrl::fromLocalFile("d:\main.qml"));
                              connect(widget, SIGNAL(destroyed()), this, SLOT(echo()));
                              layout->addWidget(widget);
                          } else {
                              layout->removeWidget(widget);
                              widget->deleteLater();
                              widget = 0;
                          }
                      }
                  
                      void echo() {
                          PROCESS_MEMORY_COUNTERS memcount;
                          if (!GetProcessMemoryInfo(GetCurrentProcess(), &memcount, sizeof(memcount))) return;
                          qDebug() << ++count << "created and destroyed," << memcount.WorkingSetSize / (1024 * 1024) << "MB memory used";
                      }
                  
                  private:
                      QVBoxLayout * layout;
                      QQuickWidget * widget;
                      int count;
                  };
                  

                  它有一个计时器,可以创建/销毁一个带有加载的 QML 文件的 QQuickWidget,虽然结果最初上升,但内存使用情况会及时稳定,表明不太可能有Qt 代码中的内存泄漏,如果您确实发生了内存泄漏,则问题不在 Qt 中,而在您自己的代码中.

                  It has a timer that creates/destroys a QQuickWidget with a loaded QML file inside, and although the results initially ramp up, the memory usage stabilizes in time, indicating it is not likely there was a memory leak in the Qt code, and that if you indeed leak memory, the fault does not lie in Qt but in your own code.

                  另外,值得一提的是,任务管理器实际上显示了比GetProcessMemoryInfo()使用更少内存的进程,我认为后者是两者更准确的衡量标准.任务管理器读数也没有显示任何内存泄漏,尽管其值波动较大.

                  Also, it is worth mentioning that the task manager actually showed the process using less memory than GetProcessMemoryInfo(), and I think the latter is the more accurate measure of the two. The task manager reading also didn't indicate any memory leaking although its value fluctuated more.

                  这是输出:

                  1 created and destroyed, 41 MB memory used
                  2 created and destroyed, 44 MB memory used
                  3 created and destroyed, 44 MB memory used
                  4 created and destroyed, 48 MB memory used
                  5 created and destroyed, 48 MB memory used
                  6 created and destroyed, 48 MB memory used
                  7 created and destroyed, 48 MB memory used
                  8 created and destroyed, 48 MB memory used
                  9 created and destroyed, 48 MB memory used
                  10 created and destroyed, 48 MB memory used
                  11 created and destroyed, 52 MB memory used
                  12 created and destroyed, 52 MB memory used
                  13 created and destroyed, 52 MB memory used
                  14 created and destroyed, 52 MB memory used
                  15 created and destroyed, 52 MB memory used
                  16 created and destroyed, 52 MB memory used
                  17 created and destroyed, 52 MB memory used
                  18 created and destroyed, 52 MB memory used
                  19 created and destroyed, 52 MB memory used
                  20 created and destroyed, 52 MB memory used
                  21 created and destroyed, 53 MB memory used
                  ...
                  50 created and destroyed, 53 MB memory used
                  ...
                  100 created and destroyed, 53 MB memory used
                  ...
                  200 created and destroyed, 53 MB memory used
                  ...
                  500 created and destroyed, 53 MB memory used
                  

                  这篇关于在 Qt5.3(mingw32) 中删除 QQuickView 的内存管理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                • <tfoot id='RUAWm'></tfoot>
                    <tbody id='RUAWm'></tbody>
                    <bdo id='RUAWm'></bdo><ul id='RUAWm'></ul>

                          <small id='RUAWm'></small><noframes id='RUAWm'>

                        • <i id='RUAWm'><tr id='RUAWm'><dt id='RUAWm'><q id='RUAWm'><span id='RUAWm'><b id='RUAWm'><form id='RUAWm'><ins id='RUAWm'></ins><ul id='RUAWm'></ul><sub id='RUAWm'></sub></form><legend id='RUAWm'></legend><bdo id='RUAWm'><pre id='RUAWm'><center id='RUAWm'></center></pre></bdo></b><th id='RUAWm'></th></span></q></dt></tr></i><div id='RUAWm'><tfoot id='RUAWm'></tfoot><dl id='RUAWm'><fieldset id='RUAWm'></fieldset></dl></div>
                        • <legend id='RUAWm'><style id='RUAWm'><dir id='RUAWm'><q id='RUAWm'></q></dir></style></legend>