Skip to content

Commit

Permalink
Add clear memory button.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaurycyLiebner committed Jan 6, 2022
1 parent 0117c34 commit 57cf06d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/app/GUI/usagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Private/Tasks/taskscheduler.h"
#include "Private/Tasks/complextask.h"
#include "conncontextptr.h"
#include "memoryhandler.h"

#include <QTimer>
#include <QLocale>
Expand Down Expand Up @@ -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);

Expand All @@ -160,6 +168,8 @@ UsageWidget::UsageWidget(QWidget * const parent) : QStatusBar(parent) {

addPermanentWidget(mRamLabel);

addPermanentWidget(clearRamButton);

setThreadsTotal(QThread::idealThreadCount());

connect(TaskScheduler::instance(), &TaskScheduler::hddUsageChanged,
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/memoryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ MemoryHandler::~MemoryHandler() {
delete mMemoryChecker;
}

void MemoryHandler::clearMemory() {
freeMemory(NORMAL_MEMORY_STATE, longB(std::numeric_limits<qint64>::max()));
}

MemoryState MemoryHandler::sMemoryState() {
return sInstance->mMemoryState;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/memoryhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class MemoryHandler : public QObject {
explicit MemoryHandler(QObject * const parent = nullptr);
~MemoryHandler();

void clearMemory();

static MemoryHandler *sInstance;
static MemoryState sMemoryState();
signals:
Expand Down

0 comments on commit 57cf06d

Please sign in to comment.