Results 1 to 11 of 11

Thread: Memory is increasing when loading a QML page but not freed completely after closing

  1. #1
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Exclamation Memory is increasing when loading a QML page but not freed completely after closing

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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,
    _

  3. #3
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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,
    _

  5. #5
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    Quote Originally Posted by mkreddy View Post
    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.

    Quote Originally Posted by mkreddy View Post
    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,
    _

  7. #7
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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,
    _

  9. #9
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    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.

  10. #10
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    I am attaching the sample project. Please have a look and suggest me what is wrong in my code.
    Attached Files Attached Files

  11. #11
    Join Date
    Mar 2016
    Location
    India
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5
    Platforms
    Unix/X11

    Default Re: Memory is increasing when loading a QML page but not freed completely after closi

    Any one has any suggestion...??

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

    Please suggest me some thing.

Similar Threads

  1. Memory increasing
    By codeman in forum Qt Quick
    Replies: 2
    Last Post: 4th September 2015, 15:57
  2. Replies: 1
    Last Post: 26th August 2013, 10:14
  3. Replies: 3
    Last Post: 15th February 2012, 00:09
  4. Memory returned for child widgets after closing
    By koan in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2011, 16:36
  5. Need your help... loading image on my widgetstack page..
    By megabeat in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2007, 15:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.