How to detect memory leak on Symbian?
-
I've tested my app with Glowcode utility on windows XP SP3(Debug with ms vc++2008), no memory leak found.
In my code, I use pointer variable and delete them after use.
When app started,main window displayed, free phone memory reduced about 17 MB,
With this app, when I deploy on symbian (Nokia E72,E71), Qt 4.6.2, QtMobility 1.1, if I call a test function many times, after each call, free memory on phone go down (Im using RnD Tools-PerfMon).If Call times reach about tens, the APP crash.
Main function below:
@#include <QtGui/QApplication>
#include "compileroption.h"
#include "kqxsmainwindow.h"
#ifdef VC2008
#include "wmainwindow.h"
#endif
#include <QString>
#include <QMessageBox>
#include <QtSql>
QSqlDatabase g_db;
int main(int argc, char *argv[])
{
// QT block
#ifndef VC2008
{
QApplication a(argc, argv);
g_db=QSqlDatabase::addDatabase("QSQLITE");
if (!g_db.isValid())
QMessageBox::critical(NULL,QString::fromUtf8("Lỗi"),QString::fromUtf8("Driver CSDL:")
+g_db.lastError().text()
);
g_db.setDatabaseName("data.db");
if(!g_db.open())
{
QMessageBox::critical(NULL,QString::fromUtf8("Lỗi"),QString::fromUtf8("Lỗi kết nối:")
+g_db.lastError().text());
}
kqxsMainWindow w;
#if (defined (Q_OS_SYMBIAN) || defined (Q_OS_LINUX))
w.showMaximized();
#else
w.showMaximized();
#endifreturn a.exec(); } // end QT
#else
/*VC++ block */
{
QApplication a(argc, argv);
QString s,o;
g_db=QSqlDatabase::addDatabase("QSQLITE");
if (!g_db.isValid())
QMessageBox::critical(NULL,QString::fromUtf8("Lỗi"),QString::fromUtf8("Driver CSDL:")
+g_db.lastError().text()
);
g_db.setDatabaseName("data.db");
if(!g_db.open())
{
QMessageBox::critical(NULL,QString::fromUtf8("Lỗi"),QString::fromUtf8("Lỗi kết nối:")
+g_db.lastError().text()
);
}
WMainWindow w;
#if (defined (Q_OS_SYMBIAN) || defined (Q_OS_LINUX))
w.showMaximized();
#else
w.showMaximized();
#endifreturn a.exec(); } // end VC++
#endif
}@
Have any way to find and fix problem?
Thanks you very much. -
It doesn't need to be a proper leak (losing references to allocated pointers) to see your memory not being freed.
On linux/maemo/meego, I would recommend you to run your code with valgrind (using memcheck and massif modules) to see exactly which part of your memory is increasing. For sure there's a equivalent tool for windows/symbian.
-
Symbian way of writing the code is not like any other platforms. Memory Management is an integral part of the OS architecture. If you use resource hungry classes, make sure you reuse them rather than creating them very often. Also prefer to create using new operator rather than creating on the stack, because stack is very precious. If you run on a Symbian emulator (you will get S60 5th edition SDK from forum nokia), you can get the memory leaks and "ALLOC" errors with the memory address. After that you can use HookLogger to detect where exactly the leak has occured ( see http://wiki.forum.nokia.com/index.php/Detecting_memory_leaks_with_HookLogger about hooklogger). Qt classes on Symbian do have some memory leaks especially resource handle classes, so you can count them too for your issue.