PDA

View Full Version : Memory is increasing when loading a QML page but not freed completely after closing



mkreddy
25th March 2016, 11:03
Hello Friends,

I have observed a mysterious increase of memory while browsing through QML pages of my application.
The observation was as follows:

I started the application and checked for memory
I loaded a QML page (Normally using Loader or Stackview) and checked for memory
Memory increased 2-9 MB depending on the page.
After closing the page 1-3 MB of memory was still not freed, still under usage(Free memory on system got reduced).
If we continuously browse through the application, After some time around 1 hour system memory was full and leading to application crash

My checking with the memory tools on the embedded board I observed Heap memory was getting Increased.

Please help me in solving this issue.

Specifications :

Used Qt5.3.2
QtQuick 2.3
Running the application on QNX Platform


Thanks in advance
Murali Krishna

anda_skoa
25th March 2016, 14:12
Does the page instantiate any custom types? I.e. anything registered with qmlRegisterType() or similar functions?

Have you run the application through a leak checker, e.g. Valgrind on Linux?

Cheers,
_

mkreddy
28th March 2016, 04:08
Hello,

Thanks for the reply.

I using qmlRegisterType() objects of some classes to read variables.
Except that all other components are normal either QML components or custom QML components.

I am running valgrind on the application but there are no leak in c++.

Regards
Murali

anda_skoa
28th March 2016, 10:26
Hmm, are you keeping references to elements/screens that are no longer needed, prohibiting their garbage collection?

Have you checked if explicitly triggering garbage collection via Qt.gc() changes anything?

Cheers,
_

mkreddy
28th March 2016, 11:08
Probably I am not keeping any of the references. I am using loader or stackview to load the qml page.
I didn't tried calling gc() externally.

I am using Qt5.3.2 and I am loading all the resources externally. Not using qrc for loading either qml or Images.

anda_skoa
28th March 2016, 11:43
Probably I am not keeping any of the references. I am using loader or stackview to load the qml page.

That sounds fine.
I assume you are using "push" and "pop" on the stack view, so "pop" would have discarded the references to the previous top most page.



I am using Qt5.3.2 and I am loading all the resources externally. Not using qrc for loading either qml or Images.
I don't think that would make any difference.

If you are loading a lot of different types, then one thing that might increasingly consume memory is the component cache.
See QQmlEngine::clearComponentCache().

Cheers,
_

mkreddy
28th March 2016, 12:47
I tried using QQmlEngine::clearComponentCache(). But it is destroying the entire data hence crashing the application.

Could you please provide me some sample how can I use the QQmlEngine::clearComponentCache().

I tried using cashe: false and asynchronous: true in Image component. Its giving some positive result but not solving the problem completely.

Regards,
Murali Krishna

anda_skoa
28th March 2016, 15:59
Ah, looks like that was the wrong one. Try trimComponentCache().

In any case you probably need to look at this with a memory profile to see where the memory is allocated and check if you assumed it would be deallocated but wasn't.

Cheers,
_

mkreddy
28th March 2016, 17:51
Yeah sure I will use memory profile to check whats going wrong.
I observed some thing strange with a sample application which has the 2 qml pages which are loaded from main.qml. The main.qml contains two rectangle components and each qml has 4 Image components. I am loading these pages with Loader.

If I load this application I observed around 1.2 MB of increase in memory and then on close of these pages I didn't observed any change in memory.
After using cashe: false and asynchronous: true It has reduced the memory and around 0.1 -0.2 MB remains there.

I introduced 2 Text components and observed the memory. It increased 2.5-3 MB. after closing the loaded QML pages The memory reduced from 2.5 MB to 0.8 MB.

So with each text component there is a leak of around 0.4 MB. I tried using clearComponentCache(). But I didn't observed any progress.

mkreddy
29th March 2016, 08:56
I am attaching the sample project. Please have a look and suggest me what is wrong in my code.

mkreddy
1st April 2016, 13:30
Any one has any suggestion...??

I tried clearcomponentcache(), trimcomponentcache()
but I didn't find any result.

Please suggest me some thing.