
Originally Posted by
jacek
If you want to delete an object you no longer use, you have to do that before it goes out of scope, because you won't be able to reach it later.
In this case you don't have to delete the object that tempQTreeWidgeItem points to, because you add it to thetwmTreeWidget, which is responsible for deleting it.
Thanks so much for the explanetion.
Get back at my memory leak cos i'm not able to understand where i'm getting wrong.
This is a little piece of valgrind command report:
==16797== 2848 (16 direct, 2832 indirect) bytes in 4 blocks are definitely lost in loss record 75 of 144
==16797== at 0x1B90939A: operator new(unsigned) (vg_replace_malloc.c:132)
==16797== by 0x818DE38
: twmConfigObject
::getPoolIconTooltip(int,
QString) (twmConfig.
cpp:4968) ==16797== by 0x81ADCB9
: twmConfigObject
::setupPoolsGetTreeView(QTreeWidget*,
bool) (twmConfig.
cpp:1210) ==16797== by 0x80BA4D0: twmMainWindow::setupPools(bool) (twmMainWindow.cpp:1387)
==16797== by 0x812DE02
: twmMainWindow
::twmMainWindow(QWidget*) (twmMainWindow.
cpp:54) ==16797== by 0x80A0317: main (trm.cpp:62)
==16797== 2848 (16 direct, 2832 indirect) bytes in 4 blocks are definitely lost in loss record 75 of 144
==16797== at 0x1B90939A: operator new(unsigned) (vg_replace_malloc.c:132)
==16797== by 0x818DE38: twmConfigObject::getPoolIconTooltip(int, QString) (twmConfig.cpp:4968)
==16797== by 0x81ADCB9: twmConfigObject::setupPoolsGetTreeView(QTreeWidget*, bool) (twmConfig.cpp:1210)
==16797== by 0x80BA4D0: twmMainWindow::setupPools(bool) (twmMainWindow.cpp:1387)
==16797== by 0x812DE02: twmMainWindow::twmMainWindow(QWidget*) (twmMainWindow.cpp:54)
==16797== by 0x80A0317: main (trm.cpp:62)
To copy to clipboard, switch view to plain text mode
I think that the problem is in my twmConfigObject::getPoolIconTooltip(int, QString) method, and down here the method's code:
QString twmConfigObject
::getPoolIconTooltip ( int theStatus ,
QString poolName
) {
countNotSync( TWMACTUALMODE__POOLS , false , & difference );
switch ( theStatus )
{
case POOLSTATUS__UNDEF:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr
( "Pool %1 status is: Undefined - %2 difference" ).
arg ( poolName
).
arg ( difference
) ) );
}
else
{
return ( QString ( tr
( "Pool %1 status is: Undefined" ).
arg ( poolName
) ) );
}
break;
case POOLSTATUS__INCOMPLETESHARE:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr
( "Pool %1 status is: Incomplete share - %2 difference" ).
arg ( poolName
).
arg ( difference
) ) );
}
else
{
return ( QString ( tr
( "Pool %1 status is: Incomplete share" ).
arg (poolName
) ) );
}
break;
case POOLSTATUS__SHARED:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr
( "Pool %1 status is: Shared - %2 difference" ).
arg ( poolName
).
arg ( difference
) ) );
}
else
{
return ( QString ( tr
( "Pool %1 status is: Shared" ).
arg (poolName
) ) );
}
break;
default:
return ( QString ( tr
( "Terminal %1 status is: Undefined" ).
arg (poolName
) ) );
break;
}
}
QString twmConfigObject::getPoolIconTooltip ( int theStatus , QString poolName )
{
QString difference;
countNotSync( TWMACTUALMODE__POOLS , false , & difference );
switch ( theStatus )
{
case POOLSTATUS__UNDEF:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr ( "Pool %1 status is: Undefined - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
}
else
{
return ( QString ( tr ( "Pool %1 status is: Undefined" ).arg ( poolName ) ) );
}
break;
case POOLSTATUS__INCOMPLETESHARE:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr ( "Pool %1 status is: Incomplete share - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
}
else
{
return ( QString ( tr ( "Pool %1 status is: Incomplete share" ).arg (poolName) ) );
}
break;
case POOLSTATUS__SHARED:
if ( ! difference.isEmpty() && difference != 0)
{
return ( QString ( tr ( "Pool %1 status is: Shared - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
}
else
{
return ( QString ( tr ( "Pool %1 status is: Shared" ).arg (poolName) ) );
}
break;
default:
return ( QString ( tr ( "Terminal %1 status is: Undefined" ).arg (poolName) ) );
break;
}
}
To copy to clipboard, switch view to plain text mode
any hint?
Bookmarks