PDA

View Full Version : Let me know your valid suggession for Memory Leak ..!!!



joseph
11th December 2006, 11:42
Hai all,


Version : Qt 3.3.4
Problem : Chance for memory leak..???

This thread for just to know your valid suggestions.
I have subclassed the QTableitem like as follows....



class MyTableItem : public QTableItem
{
----

MyTableItem( QTable * table, EditType et, const QString & text ): QTableItem( table, et, text ) { }
virtual ~MyTableItem() { }
virtual alignment ( ) const;

-----

};



In run time I am calling MyTableItem( ) like as follows.....



class MyMainWindow : QMainWindow
{
MyMainWindow( ...., ..... ){ }
~MyMainWindow();
void refreshTable ();
private:
QTable m_table;

};


void MyMainWindow :: refreshTable ()
{
------
// m_table is pointer in MyMainWindow Class
m_table->setItem ( row, col , new MyTableItem( m_table , QTableItem::Never , " Text " ) );

------
// i am not using any delete for MyTableItem anywhere.
}




As Qt promises, will it kill " MyTableItem " created in "refreshTable() " after killing MyMainWindow ....???
Please let me know ..if chances for MEMORY_LEAK ....!!!!!!!
Please give me a good suggestion ...


Thanks in advance.

wysota
11th December 2006, 11:53
If Qt promises to free the memory, it will free the memory.

joseph
11th December 2006, 12:01
So i need not be worried of the MEMORY LEAK....
I did not mean that Qt will break the promises, instead just want to know your suggessions as you people are more experienced than me.

Thank you wysota

wysota
11th December 2006, 12:14
It's written in the docs more than a dozen times that Qt takes responsibility over items which have a parent set.

sunil.thaha
11th December 2006, 15:38
And to add to what wysota had said
It is a good practice to create that QTable on heap rather than declare it as QTable table;

joseph
12th December 2006, 06:39
sunil,

Actually m_table is in heap itself .Its my mistake that i didn't mentioned like this..




class MyMainWindow : QMainWindow
{
-------
--------

public :
QTable * m_table ;


};



In runtime i will call this as follows...




// m_table will be lively when the MyMainWindow is beeing created.
m_table = new Qtable( ...,... );






As Wysota told got the solution ,like m_table will be killed by the MyMainWindow , just before it's beeing killed

Thank you sunil.