Results 1 to 19 of 19

Thread: memory leak

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    39

    Default Re: memory leak

    Quote Originally Posted by jacek View Post
    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:
    Qt Code:
    1. ==16797== 2848 (16 direct, 2832 indirect) bytes in 4 blocks are definitely lost in loss record 75 of 144
    2. ==16797== at 0x1B90939A: operator new(unsigned) (vg_replace_malloc.c:132)
    3. ==16797== by 0x818DE38: twmConfigObject::getPoolIconTooltip(int, QString) (twmConfig.cpp:4968)
    4. ==16797== by 0x81ADCB9: twmConfigObject::setupPoolsGetTreeView(QTreeWidget*, bool) (twmConfig.cpp:1210)
    5. ==16797== by 0x80BA4D0: twmMainWindow::setupPools(bool) (twmMainWindow.cpp:1387)
    6. ==16797== by 0x812DE02: twmMainWindow::twmMainWindow(QWidget*) (twmMainWindow.cpp:54)
    7. ==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:
    Qt Code:
    1. QString twmConfigObject::getPoolIconTooltip ( int theStatus , QString poolName )
    2. {
    3. QString difference;
    4. countNotSync( TWMACTUALMODE__POOLS , false , & difference );
    5.  
    6. switch ( theStatus )
    7. {
    8. case POOLSTATUS__UNDEF:
    9.  
    10. if ( ! difference.isEmpty() && difference != 0)
    11. {
    12. return ( QString ( tr ( "Pool %1 status is: Undefined - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
    13. }
    14. else
    15. {
    16. return ( QString ( tr ( "Pool %1 status is: Undefined" ).arg ( poolName ) ) );
    17. }
    18. break;
    19.  
    20. case POOLSTATUS__INCOMPLETESHARE:
    21.  
    22. if ( ! difference.isEmpty() && difference != 0)
    23. {
    24. return ( QString ( tr ( "Pool %1 status is: Incomplete share - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
    25. }
    26. else
    27. {
    28. return ( QString ( tr ( "Pool %1 status is: Incomplete share" ).arg (poolName) ) );
    29. }
    30. break;
    31.  
    32. case POOLSTATUS__SHARED:
    33.  
    34. if ( ! difference.isEmpty() && difference != 0)
    35. {
    36. return ( QString ( tr ( "Pool %1 status is: Shared - %2 difference" ).arg ( poolName ).arg ( difference ) ) );
    37. }
    38. else
    39. {
    40. return ( QString ( tr ( "Pool %1 status is: Shared" ).arg (poolName) ) );
    41. }
    42. break;
    43.  
    44. default:
    45.  
    46. return ( QString ( tr ( "Terminal %1 status is: Undefined" ).arg (poolName) ) );
    47. break;
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 
    any hint?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: memory leak

    Is new operator used in countNotSync()?

  3. #3
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    39

    Default Re: memory leak

    No, i don't use any new operator in that function, but i call some other functions and there are not new statement into them.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: memory leak

    Does the leak disappear, if you comment out all of the code and add "return QString();" instead?

  5. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    39

    Default Re: memory leak

    i have a trouble to read the leak summary...
    Qt Code:
    1. #
    2. ==3325== definitely lost: 708 bytes in 77 blocks.
    3. #
    4. ==3325== indirectly lost: 22729 bytes in 420 blocks.
    5. #
    6. ==3325== possibly lost: 0 bytes in 0 blocks.
    7. #
    8. ==3325== still reachable: 728510 bytes in 26553 blocks. <-- have i lost them(728510bytes)?
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: memory leak

    Quote Originally Posted by mattia View Post
    have i lost them(728510bytes)?
    No, there's still some way to reach that data. For example Qt might store pointers somewhere inside itself.

    Whether that's a leak or not depends on whether this amount rises with time or not. For example if you have a loop where you create temporary QObjects, give them a parent and forget to delete them. You will get a leak, but the data is "reachable" all the time through the parent. On other hand you might create a single array using new operator and as long as there's only one such array you don't have a leak, even if you never free the memory it occupies.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 23:38
  2. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 17:24
  3. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 15:18
  4. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 20:42
  5. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 13:47

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.