PDA

View Full Version : Application memory increases a lot with a FileDialog: Using Loader this memory is not



ddonate
10th November 2016, 18:47
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:


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


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

anda_skoa
11th November 2016, 19:26
How did you determine that the memory was not freed? Which memory checker did you use?

Cheers,
_

ddonate
14th November 2016, 09:44
I checked Windows 'Task Manager' (Processes - Memory)

Thanks

anda_skoa
14th November 2016, 13:39
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,
_

ddonate
15th November 2016, 17:11
No, the memory of my application is increased only the first time I open the dialog (and never decreases)

anda_skoa
15th November 2016, 21:45
Then I'd say everything is fine, no?

Cheers,
_

ddonate
16th November 2016, 17:41
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?

d_stranz
16th November 2016, 19:20
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.

anda_skoa
17th November 2016, 11:24
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.



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