From bbcbe40747b5ade600a89be32c75a0f30e23510f Mon Sep 17 00:00:00 2001 From: reionwong Date: Fri, 15 Oct 2021 18:57:18 +0800 Subject: [PATCH] Reduce memory usage --- model/foldermodel.cpp | 6 ++++++ model/foldermodel.h | 2 ++ qml/Desktop/Wallpaper.qml | 3 +++ window.cpp | 2 ++ 4 files changed, 13 insertions(+) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 217c653..d6501b4 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -53,6 +53,7 @@ #include #include #include +#include // Qt Quick #include @@ -1199,6 +1200,11 @@ void FolderModel::keyboardSearch(const QString &text) } } +void FolderModel::clearPixmapCache() +{ + QPixmapCache::clear(); +} + void FolderModel::restoreFromTrash() { if (!m_selectionModel->hasSelection()) diff --git a/model/foldermodel.h b/model/foldermodel.h index 9750c3e..1fae7d5 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -209,6 +209,8 @@ public: Q_INVOKABLE void updateSelectedItemsSize(); Q_INVOKABLE void keyboardSearch(const QString &text); + Q_INVOKABLE void clearPixmapCache(); + void restoreFromTrash(); bool isDesktop() const; diff --git a/qml/Desktop/Wallpaper.qml b/qml/Desktop/Wallpaper.qml index 07f011b..ad9b21e 100644 --- a/qml/Desktop/Wallpaper.qml +++ b/qml/Desktop/Wallpaper.qml @@ -41,6 +41,9 @@ Item { clip: true cache: false + // Clear cache + onSourceChanged: dirModel.clearPixmapCache() + ColorOverlay { id: dimsWallpaper anchors.fill: parent diff --git a/window.cpp b/window.cpp index 13747ec..2d8f6ea 100644 --- a/window.cpp +++ b/window.cpp @@ -21,6 +21,7 @@ #include #include #include +#include Window::Window(QObject *parent) : QQmlApplicationEngine(parent) @@ -40,6 +41,7 @@ void Window::load(const QUrl &url) bool Window::eventFilter(QObject *obj, QEvent *e) { if (e->type() == QEvent::Close) { + QPixmapCache::clear(); clearComponentCache(); deleteLater(); e->accept();