Results 1 to 12 of 12

Thread: Dynamically loading and unloading 2 qml files from cpp

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dynamically loading and unloading 2 qml files from cpp

    Task Manager is not a very accurate way of measuring memory use. It can be an indicator of a memory leak, but it can be misleading.

    In Windows, freeing memory (using free() in C or operator delete() in C++) does not shrink the size of your program in memory. The freed memory is not released back to the OS for use by other programs, instead it is freed to the local heap used by your program so that it can be reused within your program. So the typical behavior for a leak-free C++ program if you watch Task Manager is that it will grow to a certain size and then stay there. It doesn't shrink even if it frees all of the memory allocated from the heap.

    However, if you program allocates and frees varying size chunks of memory repeatedly, the heap can become fragmented to the point that there is not enough contiguous free memory available for the next allocation, so the program has to ask for more heap from Windows. So even though there is no leak, the program continues to grow.

    QML is implemented in C++ on top of Qt's C++ libraries, as far as I know, so the same rules should apply. If you are using pure QML in your program, then the memory leak is either within the QML implementation itself or in the way you are using it.

    I think that what is likely happening with your program is that each time you swap windows, QML must ask for more memory because it is unable to find enough contiguous free memory to create the new window and all of its widgets. If you are loading the window from QML source each time you switch, then the QML engine must go through the loading, parsing, and byte code compilation each time you switch, and that probably consumes some memory. The QML engine doesn't "remember" that you are using the same two files over and over again; each one is a brand new file as far as it is concerned.

    These kinds of problems are why I advised against doing this in my first answer to your thread.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    gowreesh (1st June 2020)

Similar Threads

  1. Active Qt: crash while unloading Qt Core DLL
    By ivigasin in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2015, 11:58
  2. Dynamically loading libraries
    By januszmk in forum Newbie
    Replies: 5
    Last Post: 4th February 2013, 16:44
  3. Remove library after unloading
    By mvw in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2010, 10:06
  4. Dynamically Loading UI With Unspecified Slots
    By spraff in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2010, 10:46
  5. Dynamically Loading a QMainWindow?
    By natron in forum Newbie
    Replies: 10
    Last Post: 21st July 2006, 01:15

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.