diff options
author | hjk <hjk@qt.io> | 2022-08-02 11:04:10 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-08-02 11:18:12 +0000 |
commit | df4155f6178b21f3d10e38fa12ff373dd522b3a1 (patch) | |
tree | d2a94311896f21ff33e90d967f805c8ccd863ef4 /src/plugins/coreplugin/mainwindow.cpp | |
parent | 9177649cabc2aa8f023cc318237eabe72040565f (diff) |
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>
Diffstat (limited to 'src/plugins/coreplugin/mainwindow.cpp')
-rw-r--r-- | src/plugins/coreplugin/mainwindow.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index ae51062df2..b2474d5a0a 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -113,6 +113,10 @@ #include <QVersionNumber> #include <QWindow> +#ifdef Q_OS_LINUX +#include <malloc.h> +#endif + using namespace ExtensionSystem; using namespace Utils; @@ -228,6 +232,13 @@ MainWindow::MainWindow() }); connect(dropSupport, &DropSupport::filesDropped, this, &MainWindow::openDroppedFiles); + +#ifdef Q_OS_LINUX + 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); }); +#endif } NavigationWidget *MainWindow::navigationWidget(Side side) const @@ -367,6 +378,12 @@ void MainWindow::restart() exit(); } +void MainWindow::restartTrimmer() +{ + if (!m_trimTimer.isActive()) + m_trimTimer.start(); +} + void MainWindow::closeEvent(QCloseEvent *event) { const auto cancelClose = [event] { @@ -419,6 +436,18 @@ void MainWindow::closeEvent(QCloseEvent *event) alreadyClosed = true; } +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + restartTrimmer(); + AppMainWindow::keyPressEvent(event); +} + +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + restartTrimmer(); + AppMainWindow::mousePressEvent(event); +} + void MainWindow::openDroppedFiles(const QList<DropSupport::FileSpec> &files) { raiseWindow(); |