-1

The app is memory leaking, so as a temporary solution I would check how much memory it takes, kill the process and restart the app.

Is there any easy way to do that?

Thank you

alexg
  • 902
  • 11
  • 37
  • Why do you need to do this rather than fixing the leak by introspecting the valgrind or similar output? Anyway, couldn't you write a wrapper for your application which calls the "free" util or use "/proc/meminfo", closes your application, and then restarts it? It is hard to do properly for cross-platform, but it is certainly possible. – László Papp Sep 27 '13 at 21:56

3 Answers3

1

You should fix the memory leak. Any way if you want to restart your application, you can use QProcess::startDetached to run an instance of your application in a new process and detach from it. After that you should exit the application.

This will restart your application :

QProcess process;
process.startDetached("myApp",QStringList());

qApp->quit();

Here myApp is the name of the executable file of the application. On Windows it can be myApp.exe.

Nejat
  • 31,784
  • 12
  • 106
  • 138
0

You could override new and delete to keep allocation statistics for the program and then when a threshold is reached based on available mem, abort(). Then in an external script you could restart.

Also see the excellent gimli monitor, here: https://bitbucket.org/wez/gimli/wiki/Monitor

rileyberton
  • 485
  • 3
  • 5
0

To restart application by itself, try:

#include <QApplication>
#include <QProcess>

...

// restart:
qApp->quit();
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
Jake W
  • 2,788
  • 34
  • 39