0

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

Diego
  • 336
  • 2
  • 21
  • try loaderFileDialog.destroy() – faraza Nov 10 '16 at 23:07
  • Thanks but it does not seem to work, the memory comsumption keeps high after closing the dialog... In fact, if I add the line in the 'onRejected' or 'onAccepted', I can not open the dialog again clicking the button (null) – Diego Nov 11 '16 at 07:29
  • read this [QML - controlling-element-lifetime](http://doc.qt.io/qt-5/qtquick-performance.html#controlling-element-lifetime) – Redanium Nov 11 '16 at 13:49
  • Thanks for the link. I am using Loader as it says there, and I reset the source when unused, but the memory does not decrease. It seems it is not destroyed... If I use 'destroy()' explicitly, my Loader seems to be deleted, and when I press the button again, I get an error (null object) and my dialog can not be displayed again. And the memory also keeps high with the destroy()... – Diego Nov 14 '16 at 08:50
  • Have you checked the `MyFileDialog.qml` for any memory leaks? And have you checked whether the memory is really used, or just not released to the OS again? It might be a *feature* of the Qt-Version you are using. https://www.youtube.com/watch?v=77LH_I_Vx5E – derM - not here for BOT dreams Nov 14 '16 at 13:46
  • MyFileDialog.qml only contains a Qt FileDialog component inside... So it could be a Qt bug, but it seems to be really a simple thing to have a bug, isn't it? I am using Qt 5.6.2 – Diego Nov 15 '16 at 16:15

0 Answers0