Results 1 to 6 of 6

Thread: Let me know your valid suggession for Memory Leak ..!!!

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Qt products
    Qt3 Qt4
    Thanks
    12
    Thanked 1 Time in 1 Post

    Question Let me know your valid suggession for Memory Leak ..!!!

    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....

    Qt Code:
    1. class MyTableItem : public QTableItem
    2. {
    3. ----
    4.  
    5. MyTableItem( QTable * table, EditType et, const QString & text ): QTableItem( table, et, text ) { }
    6. virtual ~MyTableItem() { }
    7. virtual alignment ( ) const;
    8.  
    9. -----
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. class MyMainWindow : QMainWindow
    2. {
    3. MyMainWindow( ...., ..... ){ }
    4. ~MyMainWindow();
    5. void refreshTable ();
    6. private:
    7. QTable m_table;
    8.  
    9. };
    10.  
    11.  
    12. void MyMainWindow :: refreshTable ()
    13. {
    14. ------
    15. // m_table is pointer in MyMainWindow Class
    16. m_table->setItem ( row, col , new MyTableItem( m_table , QTableItem::Never , " Text " ) );
    17.  
    18. ------
    19. // i am not using any delete for MyTableItem anywhere.
    20. }
    To copy to clipboard, switch view to plain text mode 


    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.
    Last edited by jacek; 11th December 2006 at 13:07. Reason: changed [html] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Let me know your valid suggession for Memory Leak ..!!!

    If Qt promises to free the memory, it will free the memory.

  3. The following user says thank you to wysota for this useful post:

    joseph (11th December 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    157
    Qt products
    Qt3 Qt4
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Let me know your valid suggession for Memory Leak ..!!!

    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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Let me know your valid suggession for Memory Leak ..!!!

    It's written in the docs more than a dozen times that Qt takes responsibility over items which have a parent set.

  6. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Let me know your valid suggession for Memory Leak ..!!!

    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;
    We can't solve problems by using the same kind of thinking we used when we created them

  7. #6
    Join Date
    Feb 2006
    Posts
    157
    Qt products
    Qt3 Qt4
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Let me know your valid suggession for Memory Leak ..!!!

    sunil,

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

    Qt Code:
    1. class MyMainWindow : QMainWindow
    2. {
    3. -------
    4. --------
    5.  
    6. public :
    7. QTable * m_table ;
    8.  
    9.  
    10. };
    To copy to clipboard, switch view to plain text mode 

    In runtime i will call this as follows...
    Qt Code:
    1. // m_table will be lively when the MyMainWindow is beeing created.
    2. m_table = new Qtable( ...,... );
    To copy to clipboard, switch view to plain text mode 




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

    Thank you sunil.
    Last edited by jacek; 12th December 2006 at 11:31. Reason: changed [html] to [code]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.