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:
Code:
import QtQuick 2.0
import QtQuick.Controls 1.4
Item {
width: 400
height: 400
Loader {
id: loaderFileDialog
}
Connections {
target: loaderFileDialog.item
onAccepted: {
loaderFileDialog.source = "";
console.log("onAccepted");
}
onRejected: {
loaderFileDialog.source = "";
console.log("onCancel");
}
}
Button {
anchors.centerIn: parent
width: 100
height: 50
text: "Open file";
onClicked: {
loaderFileDialog.source = "qrc:/MyFileDialog.qml";
loaderFileDialog.item.visible = true;
}
}
}
And my QML file with the FileDialog: MyFileDialog.qml
Code:
import QtQuick 2.1
import QtQuick.Dialogs 1.0
FileDialog {
id: fileDialog
}
What am I doing wrong? Any idea or suggestion?
Thanks a lot in advance,
Diego
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,
_
Re: Application memory increases a lot with a FileDialog: Using Loader this memory is
I checked Windows 'Task Manager' (Processes - Memory)
Thanks
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,
_
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)
Re: Application memory increases a lot with a FileDialog: Using Loader this memory is
Then I'd say everything is fine, no?
Cheers,
_
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?
Re: Application memory increases a lot with a FileDialog: Using Loader this memory is
Quote:
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).
Quote:
(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.
Re: Application memory increases a lot with a FileDialog: Using Loader this memory is
Quote:
Originally Posted by
ddonate
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
(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,
_