diff --git a/src/app/GUI/usagewidget.cpp b/src/app/GUI/usagewidget.cpp index 2e9e9d271..5440ed1cb 100755 --- a/src/app/GUI/usagewidget.cpp +++ b/src/app/GUI/usagewidget.cpp @@ -20,6 +20,7 @@ #include "Private/Tasks/taskscheduler.h" #include "Private/Tasks/complextask.h" #include "conncontextptr.h" +#include "memoryhandler.h" #include #include @@ -146,6 +147,13 @@ UsageWidget::UsageWidget(QWidget * const parent) : QStatusBar(parent) { mRamLabel = new QLabel(this); + const auto clearRamButton = new QPushButton("clear memory", this); + connect(clearRamButton, &QPushButton::clicked, + this, []() { + const auto m = MemoryHandler::sInstance; + m->clearMemory(); + }); + addPermanentWidget(gpuLabel); addPermanentWidget(mGpuBar); @@ -160,6 +168,8 @@ UsageWidget::UsageWidget(QWidget * const parent) : QStatusBar(parent) { addPermanentWidget(mRamLabel); + addPermanentWidget(clearRamButton); + setThreadsTotal(QThread::idealThreadCount()); connect(TaskScheduler::instance(), &TaskScheduler::hddUsageChanged, @@ -200,7 +210,7 @@ void UsageWidget::setTotalRam(const qreal totalRamMB) { } void UsageWidget::addComplexTask(ComplexTask * const task) { - for(const auto wid : mTaskWidgets) { + for(const auto wid : qAsConst(mTaskWidgets)) { if(wid->isHidden()) { return wid->setComplexTask(task); } diff --git a/src/app/memoryhandler.cpp b/src/app/memoryhandler.cpp index 5100d7abc..108c3a597 100755 --- a/src/app/memoryhandler.cpp +++ b/src/app/memoryhandler.cpp @@ -60,6 +60,10 @@ MemoryHandler::~MemoryHandler() { delete mMemoryChecker; } +void MemoryHandler::clearMemory() { + freeMemory(NORMAL_MEMORY_STATE, longB(std::numeric_limits::max())); +} + MemoryState MemoryHandler::sMemoryState() { return sInstance->mMemoryState; } diff --git a/src/app/memoryhandler.h b/src/app/memoryhandler.h index 0663f874a..f8187b0d4 100755 --- a/src/app/memoryhandler.h +++ b/src/app/memoryhandler.h @@ -26,6 +26,8 @@ class MemoryHandler : public QObject { explicit MemoryHandler(QObject * const parent = nullptr); ~MemoryHandler(); + void clearMemory(); + static MemoryHandler *sInstance; static MemoryState sMemoryState(); signals: