another chapter to this story
The memory leakage is due a combination threads and timers (can I use a Qtimer outside a Qthread?? this is the point: it seems a huge limitation of Qtimer indeed ...)
Below the example code: the memory in growing everytime m_progSupply->start() is executing by the main (i can see this using the debugger but i cannot get into the code since this is a thread).
I cannot see any reason for this: timer instance is correctly deleted as far as i can see
main()
{
....
m_progSupply->start(); // progSupply is a parent class of Qthread
.....
}
---------------------------------------------------------------------------
progSupply
::progSupply(QWidget *parent, Qt
::WFlags flags
){
....
}
void progSupply::run()
{
m_UartTimer
= new QTimer(this);
connect(m_UartTimer, SIGNAL(timeout()), this, SLOT(TimeOutUart()), Qt::DirectConnection);
m_UartTimer->setSingleShot(false);
StartTimeUart();
exec();
}
void progSupply::StartTimeUart()
{
m_UartTimer->start(UART_TIMEOUT);
}
void progSupply::TimeOutUart()
{
m_UartTimer->stop();
checksUart();
}
void progSupply::checksUart()
{
m_UartTimer->stop();
if (data == false) && (m_repeat == true)
{
StartTimeUart(); // re-arm timer
return;
}
else
{
emit endProgrammerSignal("OK");
if (m_UartTimer)
delete(m_UartTimer);
}
}
main()
{
....
m_progSupply->start(); // progSupply is a parent class of Qthread
.....
}
---------------------------------------------------------------------------
progSupply::progSupply(QWidget *parent, Qt::WFlags flags)
: QThread(parent)
{
....
}
void progSupply::run()
{
m_UartTimer = new QTimer(this);
connect(m_UartTimer, SIGNAL(timeout()), this, SLOT(TimeOutUart()), Qt::DirectConnection);
m_UartTimer->setSingleShot(false);
StartTimeUart();
exec();
}
void progSupply::StartTimeUart()
{
m_UartTimer->start(UART_TIMEOUT);
}
void progSupply::TimeOutUart()
{
m_UartTimer->stop();
checksUart();
}
void progSupply::checksUart()
{
m_UartTimer->stop();
if (data == false) && (m_repeat == true)
{
StartTimeUart(); // re-arm timer
return;
}
else
{
emit endProgrammerSignal("OK");
if (m_UartTimer)
delete(m_UartTimer);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks