Results 1 to 9 of 9

Thread: Application memory increases a lot with a FileDialog: Using Loader this memory is not

  1. #1
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Application memory increases a lot with a FileDialog: Using Loader this memory is not

    Hi,

    I have a simple QML application where I open a FileDialog when a button is pressed.

    I have realized that when I open the FileDialog the current application memory is increased a lot (12 Mb only with the dialog), so I have added a Loader to the FileDialog. Therefore, the memory is only increased when I open the dialog. But my problem is that I can not free this memory, even setting the Loader source to "".

    My test file:

    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.4
    3.  
    4. Item {
    5. width: 400
    6. height: 400
    7.  
    8. Loader {
    9. id: loaderFileDialog
    10. }
    11.  
    12. Connections {
    13. target: loaderFileDialog.item
    14. onAccepted: {
    15. loaderFileDialog.source = "";
    16. console.log("onAccepted");
    17. }
    18. onRejected: {
    19. loaderFileDialog.source = "";
    20. console.log("onCancel");
    21. }
    22. }
    23.  
    24. Button {
    25. anchors.centerIn: parent
    26.  
    27. width: 100
    28. height: 50
    29.  
    30. text: "Open file";
    31.  
    32. onClicked: {
    33. loaderFileDialog.source = "qrc:/MyFileDialog.qml";
    34. loaderFileDialog.item.visible = true;
    35. }
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    And my QML file with the FileDialog: MyFileDialog.qml

    Qt Code:
    1. import QtQuick 2.1
    2. import QtQuick.Dialogs 1.0
    3.  
    4. FileDialog {
    5. id: fileDialog
    6. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong? Any idea or suggestion?

    Thanks a lot in advance,
    Diego

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

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    How did you determine that the memory was not freed? Which memory checker did you use?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    I checked Windows 'Task Manager' (Processes - Memory)

    Thanks

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

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    Ok, so you don't know if the memory has been freed or not, just that the operating system hasn't reduced the memory allocated to the process.

    Does the memory increase another 12 MB when you open the dialog again?

    Cheers,
    _

  5. #5
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    No, the memory of my application is increased only the first time I open the dialog (and never decreases)

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

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    Then I'd say everything is fine, no?

    Cheers,
    _

  7. #7
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    The memory is increased when I set a QML file path to my Loader, but I thought the memory used when loaded is freed when setting the loader source to "" (so the memory used by my application decreases), isn't it correct?

  8. #8
    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: Application memory increases a lot with a FileDialog: Using Loader this memory is

    The memory is increased when I set a QML file path to my Loader, but I thought the memory used when loaded is freed when setting the loader source to ""
    Yes, the memory is probably freed (or more accurately, marked as "free" in the memory heap).

    (so the memory used by my application decreases), isn't it correct?
    No, not necessarily. The memory that has been freed is marked as available, but if other memory that has been allocated from the heap that is still in use, this free memory is probably surrounded by this other memory. Windows will not rearrange the heap when memory is freed, so in this case your program's memory footprint will not decrease.

    In addition, your program will likely keep some extra memory available on the program's heap so it doesn't have to go back to Windows' memory manager to ask to grow the heap. This allows your program to run faster by avoiding system calls, at the expense of using slightly more memory. 12MB is a tiny amount of memory, actually.

    Task Manager is actually a terrible tool to use for monitoring memory usage. It is not granular enough to give accurate readings, and it is not updated frequently enough when a program's memory usage changes rapidly.
    <=== 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.

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

    Default Re: Application memory increases a lot with a FileDialog: Using Loader this memory is

    Quote Originally Posted by ddonate View Post
    The memory is increased when I set a QML file path to my Loader, but I thought the memory used when loaded is freed when setting the loader source to ""
    It is. As you found out it is not increased again when you load again, so the memory must have been released before the second loading.

    Quote Originally Posted by ddonate View Post
    (so the memory used by my application decreases), isn't it correct?
    Yes, but since you haven't use any memory measurement tool you are not seeing it.

    See d_stranz's post for some reasons why the system might not have reclaimed the freed memory.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 7th September 2011, 14:12
  2. webkit- Memory consumption increases per page load ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2011, 10:55
  3. application seems to eat up memory
    By priceey in forum Newbie
    Replies: 5
    Last Post: 8th December 2010, 12:12
  4. Replies: 3
    Last Post: 6th January 2010, 17:55
  5. I have memory leak on every Qt3/4 application, Qt bug?
    By saugumas in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2007, 20:33

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.