QThread: Free heap memory?
-
I'm developing my application using
QThreadfollowing this tutorial here.// --- PROCESS --- // Start processing data. void Plugin::process() { // allocate resources using new here double* B = new double[n]; qDebug("Hello World!"); emit finished(); }
QThread* thread = new QThread; worker->moveToThread(thread); connect(worker, &Plugin_API::sendMsg, this, &job_manager::pluginMessage); connect(thread, &QThread::started, worker, &Plugin_API::start); connect(worker, &Plugin_API::finished, thread, &QThread::quit); connect(worker, &Plugin_API::finished, selectedPlugin, &Plugin_API::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start();My question is:
Should I manually free theBvariable memory? Or when theprocess()method ends, all allocated heap memory is cleared automatically? -
I'm developing my application using
QThreadfollowing this tutorial here.// --- PROCESS --- // Start processing data. void Plugin::process() { // allocate resources using new here double* B = new double[n]; qDebug("Hello World!"); emit finished(); }
QThread* thread = new QThread; worker->moveToThread(thread); connect(worker, &Plugin_API::sendMsg, this, &job_manager::pluginMessage); connect(thread, &QThread::started, worker, &Plugin_API::start); connect(worker, &Plugin_API::finished, thread, &QThread::quit); connect(worker, &Plugin_API::finished, selectedPlugin, &Plugin_API::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start();My question is:
Should I manually free theBvariable memory? Or when theprocess()method ends, all allocated heap memory is cleared automatically?@fem_dev said in QThread: Free heap memory?:
all allocated heap memory is cleared automatically?
Nah fam, this is not some nice walk in the park, this is C++!
you can use
std::unique_ptr<double[]> b(new double[n]);if you want memory to be wiped automaticaly (remember to#include <memory>for that)