From d4e90780226e6e910561654cc3a574623ddfa5cc Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 12:07:45 -0400 Subject: Commit a small cleanup for the auto-loading of the apps list on the system. Going to check if this fixes the memory leak issue on some systems (have one I can test on now). --- src-qt5/core/libLumina/LuminaXDG.cpp | 12 +++++++----- src-qt5/core/libLumina/LuminaXDG.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index 48185a38..64f21743 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -20,6 +20,7 @@ XDGDesktopList::XDGDesktopList(QObject *parent, bool watchdirs) : QObject(parent synctimer = new QTimer(this); synctimer->setInterval(60000); //1 minute intervals. since the polling/update only takes a few ms, this is completely reasonable connect(synctimer, SIGNAL(timeout()), this, SLOT(updateList()) ); + keepsynced = watchdirs; if(watchdirs){ watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(watcherChanged()) ); @@ -79,12 +80,13 @@ void XDGDesktopList::updateList(){ } //If this class is automatically managing the lists, update the watched files/dirs and send out notifications if(watcher!=0){ - //qDebug() << "App List Updated:" << lastCheck << appschanged << newfiles << oldkeys; + qDebug() << "Auto App List Update:" << lastCheck << "Changes:" << appschanged;// << newfiles << oldkeys; watcher->removePaths(QStringList() << watcher->files() << watcher->directories()); watcher->addPaths(appDirs); if(appschanged){ emit appsUpdated(); } + synctimer->start(); } - synctimer->start(); + } QList XDGDesktopList::apps(bool showAll, bool showHidden){ @@ -511,15 +513,15 @@ QStringList LXDG::systemApplicationDirs(){ } XDGDesktopList* LXDG::systemAppsList(){ - static XDGDesktopList *sysapps = new XDGDesktopList(0,true); //set this to automatically update as needed + static XDGDesktopList *sysapps = 0; + if(sysapps == 0){ qDebug() << "Generating new apps list"; sysapps = new XDGDesktopList(0,true); }//set this to automatically update as needed if(sysapps->lastCheck.isNull()){ sysapps->updateList(); } //catch the first time the class was used, and prompt for an update right now return sysapps; } QList LXDG::systemDesktopFiles(bool showAll, bool showHidden){ //Quick overload for backwards compatibility which uses the static/global class for managing app entries - XDGDesktopList list(0, false); - return list.apps(showAll, showHidden); + return systemAppsList()->apps(showAll, showHidden); } QHash > LXDG::sortDesktopCats(QList apps){ diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 996e5a20..0397ce71 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -93,6 +93,7 @@ public slots: private: QFileSystemWatcher *watcher; QTimer *synctimer; + bool keepsynced; private slots: void watcherChanged(); -- cgit From 16e6d9d7ad7f342a747bef3ffcbe007ee3132ba6 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 12:19:58 -0400 Subject: Another quick fix to try and track down where Lumina is leaking memory within teh app list search routine. --- src-qt5/core/libLumina/LuminaXDG.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index 64f21743..a32273c0 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -65,6 +65,7 @@ void XDGDesktopList::updateList(){ } if(ok && !found.contains(dFile.name)){ if(!oldkeys.contains(path)){ newfiles << path; } //brand new file (not an update to a previously-read file) + else{ files.remove(path); } //just to ensure that we don't get duplicates within the Hash files.insert(path, dFile); found << dFile.name; oldkeys.removeAll(path); //make sure this key does not get cleaned up later -- cgit From 194547d321a327d6bea549a2aed047169973883b Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 13:35:25 -0400 Subject: Another small fix to try and correct the memory leak. --- src-qt5/core/libLumina/LuminaXDG.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index a32273c0..b57738c1 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -56,32 +56,34 @@ void XDGDesktopList::updateList(){ path = dir.absoluteFilePath(apps[a]); if(files.contains(path) && (files.value(path).lastRead>QFileInfo(path).lastModified()) ){ //Re-use previous data for this file (nothing changed) - dFile = files[path]; + found << files[path].name; //keep track of which files were already found ok=true; }else{ ok=false; + if(files.contains(path)){ files.remove(path); } dFile = LXDG::loadDesktopFile(path,ok); //will change the "ok" variable as needed appschanged = true; //flag that something changed - needed to load a file + if(ok && !found.contains(dFile.name)){ + if(!oldkeys.contains(path)){ newfiles << path; } //brand new file (not an update to a previously-read file) + files.insert(path, dFile); + found << dFile.name; + } } - if(ok && !found.contains(dFile.name)){ - if(!oldkeys.contains(path)){ newfiles << path; } //brand new file (not an update to a previously-read file) - else{ files.remove(path); } //just to ensure that we don't get duplicates within the Hash - files.insert(path, dFile); - found << dFile.name; - oldkeys.removeAll(path); //make sure this key does not get cleaned up later - } + oldkeys.removeAll(path); //make sure this key does not get cleaned up later } //end loop over apps } //end loop over appDirs //Save the extra info to the internal lists - if(!firstrun){ removedApps = oldkeys; }//files which were removed - if(!firstrun){ newApps = newfiles; }//files which were added + if(!firstrun){ + removedApps = oldkeys;//files which were removed + newApps = newfiles; //files which were added + } //Now go through and cleanup any old keys where the associated file does not exist anymore for(int i=0; iremovePaths(QStringList() << watcher->files() << watcher->directories()); watcher->addPaths(appDirs); if(appschanged){ emit appsUpdated(); } -- cgit From 6610dc38cfd9527038716821b5292d13d5f13ea7 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 13:57:18 -0400 Subject: Have the internal QHash run "squeeze" after every update run - just to ensure it uses as little memory as possible. --- src-qt5/core/libLumina/LuminaXDG.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index b57738c1..e500ab7e 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -89,7 +89,7 @@ void XDGDesktopList::updateList(){ if(appschanged){ emit appsUpdated(); } synctimer->start(); } - + files.squeeze(); //make sure this class uses as little memory as possible (should not be needed - but just in case...) } QList XDGDesktopList::apps(bool showAll, bool showHidden){ -- cgit From de4b5c26801cc19956d0eb1e1d109b7024c8e368 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 14:20:15 -0400 Subject: Add an "==" operator to the XDGDesktop class. Found a note in the QHash docs that any class type need this defined. --- src-qt5/core/libLumina/LuminaXDG.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 0397ce71..1720ebc5 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -68,6 +68,10 @@ public: //Constructor/destructor XDGDesktop(){} ~XDGDesktop(){} + + friend bool operator==(const XDGDesktop lhs, const XDGDesktop rhs){ + return lhs.filePath == rhs.filePath && lhs.lastRead == rhs.lastRead; + } }; // ======================== -- cgit From e24b7b3f822a55aa8210ed21d50349147426f7a3 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Sep 2016 17:08:34 -0400 Subject: Fix the memory usage issue with Lumina and the application list on the system. It no longer grows with time that I can tell, but I am sure there is some additional cleanup and optimizations which can still be done later. --- src-qt5/core/libLumina/LuminaXDG.cpp | 27 +++++++++------------------ src-qt5/core/libLumina/LuminaXDG.h | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 28 deletions(-) (limited to 'src-qt5/core') diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index e500ab7e..36b05676 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -48,7 +48,7 @@ void XDGDesktopList::updateList(){ bool firstrun = lastCheck.isNull() || oldkeys.isEmpty(); lastCheck = QDateTime::currentDateTime(); //Variables for internal loop use only (to prevent re-initializing variable on every iteration) - bool ok; QString path; QDir dir; QStringList apps; XDGDesktop dFile; + bool ok; QString path; QDir dir; QStringList apps; for(int i=0; istart(); } - files.squeeze(); //make sure this class uses as little memory as possible (should not be needed - but just in case...) } QList XDGDesktopList::apps(bool showAll, bool showHidden){ @@ -97,8 +97,8 @@ QList XDGDesktopList::apps(bool showAll, bool showHidden){ QStringList keys = files.keys(); QList out; for(int i=0; i actions; //Type 2 (LINK) variables QString url; - + //Constructor/destructor XDGDesktop(){} - ~XDGDesktop(){} - - friend bool operator==(const XDGDesktop lhs, const XDGDesktop rhs){ - return lhs.filePath == rhs.filePath && lhs.lastRead == rhs.lastRead; - } + ~XDGDesktop(){ + actions.clear(); + showInList.clear(); notShowInList.clear(); actionList.clear(); mimeList.clear(); catList.clear(); keyList.clear(); + name.clear(); genericName.clear(); comment.clear(); icon.clear(); + exec.clear(); tryexec.clear(); path.clear(); startupWM.clear(); url.clear(); + } }; // ======================== -- cgit