简体   繁体   English

Qt QML应用程序增加了内存使用率

[英]Qt qml application increasing memory usage

I created an application with Qt/QML, load a qml file with QQuickView , and with this use a Loader element for change the pages(gui) inside application, and works fine, but my problem is the increase of the program memory usage (the application starts with less of 100MB, and after 1 day, the size is about 500 MB or more), I originally write and update the model of objects in Qml (javascript), but the application grows quickly, changing to create models with C++ objects, memory usage grows less but the problem is still not solved. 我使用Qt / QML创建了一个应用程序,并使用QQuickView加载了QQuickView文件,并使用Loader元素更改了应用程序内部的pages(gui),并且工作正常,但是我的问题是程序内存使用量的增加(应用程序开始时只有不到100MB的空间,而1天后大小约为500 MB或更多),我最初是用Qml(javascript)编写和更新对象模型的,但是应用程序增长很快,更改为使用C ++对象创建模型,内存使用量增长较少,但问题仍未解决。

My model can be updated continuously (even 1 time per second), but I don't believe that be the reason of memory rises. 我的模型可以连续更新(甚至每秒更新1次),但是我不认为这是内存增加的原因。

But with that problem come other strangers behaviors is with TableView when changes to that page, the memory rises even 10 MB, I try to free memory with gc() , but i don't get successful results, and in the change of page, the memory sometimes can rise by 1 MB. 但是随着这个问题的到来,其他的陌生人的行为是TableView更改页面时,内存甚至增加了10 MB,我尝试使用gc()释放内存,但是我没有获得成功的结果,并且在页面更改中,内存有时会增加1 MB。

Note: I use a Qt 5.5, and msvc 2010. 注意:我使用Qt 5.5和msvc 2010。

You might want to check your application for memory leaks. 您可能要检查您的应用程序是否存在内存泄漏。 That sounds a little excessive, even for QML, which is not known for memory efficiency. 甚至对于QML来说,这听起来有点过分,因为内存效率并不为人所知。

Keep in mind, the QML engine will over-provision and will not release memory even when that seems the logical thing to do. 请记住,即使这似乎是合乎逻辑的事情,QML引擎也会过度配置并且不会释放内存。 I've had cases of reaching gigabytes of memory usage in QML, having tens of thousands of QML objects "alive", and upon deletion of all the objects, memory usage doesn't come anywhere near the initial memory usage. 我曾经遇到过在QML中达到千兆位内存使用的情况,有成千上万个“存活”的QML对象,并且在删除所有对象后,内存使用量不会接近初始内存使用量。 The freed memory is usually a tiny amount, for example, having 1 GB of memory worth of objects, deleting all the objects frees only like 150 MB of memory. 释放的内存通常很小,例如,具有1 GB内存的对象,删除所有对象只能释放150 MB的内存。 The good news is that memory will be reused, creating those objects again will push memory usage to the previous peak, not any further. 好消息是,内存将被重用,再次创建这些对象将使内存使用率达到先前的峰值,而不会再进一步​​。 So as far as memory in your application is concerned, you are set. 因此,就应用程序中的内存而言,您已经设置好了。

I don't know if that will stack with the rest of the OS processes, whether your application will release extra memory if your system runs out of ram. 我不知道这是否会与其余的OS进程一起使用,如果系统用完了内存,应用程序是否会释放额外的内存。

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

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