Results 1 to 3 of 3

Thread: [SOLVED] Automatic children freeing for objects derived from QObject

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [SOLVED] Automatic children freeing for objects derived from QObject

    Hello again people,

    I have created long time ago some code which overloads new, new[], delete and delete[] operators, and which keeps track of allocated / freed memory in a std::map stuff.

    My problem is, that i'm trying to use my code in my new QT application, and the result is that i get some warnings on memory leaks which i don't understand:
    for instance, if in my main window object i do:
    Qt Code:
    1. QTreeWidgetItem* pItmToAdd = new QTreeWidgetItem(pParent);
    To copy to clipboard, switch view to plain text mode 
    Do i have to delete it then? Or will QT handle this itself when "destructing" the parent QTreeWidget?
    I have the very same problem each time i "new" an object which herits of QObject:
    I have made some little KIO-like listers which are all derived from a class IFilesLister. So i get CFilesLister_File, CFilesLister_FTP, etc... The thing is, that in my application i do construct them this way:
    Qt Code:
    1. IFilesLister* pLocalLister = new CFilesLister_FTP();
    To copy to clipboard, switch view to plain text mode 
    and in the main window's destructor i do:
    Qt Code:
    1. delete pLocalLister;
    To copy to clipboard, switch view to plain text mode 
    Then, my log shows the constructor AND destructor as well:
    Qt Code:
    1. Dbg> -> An [_FTP] Files Lister object is being constructed.
    2. Dbg> Creating an instance of the internal FTP object...
    3. Dbg> The [_FTP] Files Lister is initializing it's slots...
    4. Dbg> <- The [_FTP] Files Lister object was created.
    To copy to clipboard, switch view to plain text mode 
    Then later:
    Qt Code:
    1. Dbg> -> Destructing the main application Dialog.
    2. Dbg> -> The [_FTP] Files Lister object is destroying...
    3. Dbg> <- The [_FTP] Files Lister object was destroyed.
    4. Dbg> <- Done destructing the main application Dialog.
    To copy to clipboard, switch view to plain text mode 

    So i have the "debug" proof that my objects get actually destroyed, but my memory leaks tracking system still anoys me with warnings on those pointers...

    The only explaination i have is, that because the objects pointed by my leaks manager are all derived from QObject, maybe QT delete them itself before...

    Any idea on how to solve this?
    Bye!
    Pierre.

    [EDIT:]
    Here is a sample output of my leaks tracking system:
    Qt Code:
    1. Dbg> -> Probable Memory Leaks Listing:
    2. Dbg> Src/CWndMainImpl.cpp:42 0x136736944, 36 byte(s).
    3. Dbg> Src/CWndMainImpl.cpp:33 0x136738728, 20 byte(s).
    4. Dbg> Src/CWndMainImpl.cpp:64 0x136816616, 32 byte(s).
    5. Dbg> Src/CWndMainImpl.cpp:72 0x136818288, 32 byte(s).
    6. Dbg> Src/CWndMainImpl.cpp:90 0x136820016, 32 byte(s).
    7. Dbg> Src/CWndMainImpl.cpp:98 0x136821392, 32 byte(s).
    8. Dbg> <- Total: 6 non-freed block(s), 184 byte(s)
    To copy to clipboard, switch view to plain text mode 
    Which ALL are "new"ed objects, either "native" QT or derivated from QObject...
    Last edited by hickscorp; 6th December 2006 at 23:55.

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.