Results 1 to 4 of 4

Thread: QList and garbage collection

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QList and garbage collection

    Hi,

    I have;

    Qt Code:
    1. QObject* obj = new QObject
    To copy to clipboard, switch view to plain text mode 

    And I have two seperate lists that hold address of the obj.

    I want to ask that, does QList clear, removeAt, removeAll etc. methods deletes the object itself or reference?

    If so, how Qt deletes the obj? By keeping reference(s) on it?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QList and garbage collection

    They are not getting deleted. You have to take care about that yourself. clear() just clears the list. If you also want to delete the stored items see qDeleteAll().

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QList and garbage collection

    So you say only references in the list are being removed?

    Well, what qt garbage collector does then? Is there any of it actually?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QList and garbage collection

    Yes, and Qt does not have a gc like Java. Qt does only delete the children of a QObject when it gets destroyed.

Similar Threads

  1. Garbage collector - PyQt
    By janosimas in forum Newbie
    Replies: 0
    Last Post: 11th December 2011, 11:05
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. Garbage collection
    By Septi in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 14:13
  4. QString, QStringList and garbage collection...
    By PaladinKnight in forum Newbie
    Replies: 4
    Last Post: 5th April 2010, 16:22
  5. question about garbage collection
    By Dumbledore in forum Qt Programming
    Replies: 4
    Last Post: 18th December 2007, 22:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.