forked from qt-creator/qt-creator
App: Use more local methods to trigger memory trim timer
The global event filter function is executed often, for events originating deep in the widget hierarchy even multiple times. Triggering the timer only by mouse and key presses on the main application and on texteditor is less intrusive and still happens often enough (TM). Change-Id: I848d55a347bd62d12e8523965d1750c59da33116 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -84,10 +84,6 @@
|
||||
#include "client/settings.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
using namespace ExtensionSystem;
|
||||
|
||||
enum { OptionIndent = 4, DescriptionIndent = 34 };
|
||||
@@ -757,32 +753,5 @@ int main(int argc, char **argv)
|
||||
// shutdown plugin manager on the exit
|
||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, &pluginManager, &PluginManager::shutdown);
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
class MemoryTrimmer : public QObject
|
||||
{
|
||||
public:
|
||||
MemoryTrimmer()
|
||||
{
|
||||
m_trimTimer.setSingleShot(true);
|
||||
m_trimTimer.setInterval(60000);
|
||||
// glibc may not actually free memory in free().
|
||||
connect(&m_trimTimer, &QTimer::timeout, this, [] { malloc_trim(0); });
|
||||
}
|
||||
|
||||
bool eventFilter(QObject *, QEvent *e) override
|
||||
{
|
||||
if ((e->type() == QEvent::MouseButtonPress || e->type() == QEvent::KeyPress)
|
||||
&& !m_trimTimer.isActive()) {
|
||||
m_trimTimer.start();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QTimer m_trimTimer;
|
||||
};
|
||||
MemoryTrimmer trimmer;
|
||||
app.installEventFilter(&trimmer);
|
||||
#endif
|
||||
|
||||
return restarter.restartOrExit(app.exec());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user