mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
b22f1da59e
Subsurface creates a lot of singleton instances on demand, but nothing ever deleted them. Since they are singletons, these memory allocations are technically not leaks. However, they clutter the output in valgrind and other memory analysers, hiding the real issues. The solution is to delete these items at exit. For the models and for gettextFromC, the solution is to use a QScopedPointer, which will delete its payload when it gets destroyed. For the dialogs and other widgets, we can't do that: they need to be deleted before QApplication exits, so we just set the parent in all of them to the main window. Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
27 lines
573 B
C++
27 lines
573 B
C++
#include <QCoreApplication>
|
|
#include <QString>
|
|
#include <gettextfromc.h>
|
|
|
|
const char *gettextFromC::trGettext(const char *text)
|
|
{
|
|
QByteArray &result = translationCache[QByteArray(text)];
|
|
if (result.isEmpty())
|
|
result = trUtf8(text).toUtf8();
|
|
return result.constData();
|
|
}
|
|
|
|
void gettextFromC::reset(void)
|
|
{
|
|
translationCache.clear();
|
|
}
|
|
|
|
gettextFromC* gettextFromC::instance()
|
|
{
|
|
static QScopedPointer<gettextFromC> self(new gettextFromC());
|
|
return self.data();
|
|
}
|
|
|
|
extern "C" const char *trGettext(const char *text)
|
|
{
|
|
return gettextFromC::instance()->trGettext(text);
|
|
}
|