Results 1 to 8 of 8

Thread: Memory management in Qt?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Memory management in Qt?

    I'm quite new to Qt and am wondering on some basic stuff with memory management and the life of objects. When do I need to delete / destroy my objects? Is any of this handled automatically?

    In the example below, which of the objects I create do I need to delete? What happens to the instance variable myOtherClass when myClass is destroyed? What happens if I don't delete / destroy my objects at all, will that be a problem to memory?

    in MyClass.h:
    Qt Code:
    1. class MyClass
    2. {
    3.  
    4. public:
    5. MyClass();
    6. ~MyClass();
    7. MyOtherClass *myOtherClass;
    8. };
    To copy to clipboard, switch view to plain text mode 

    in MyClass.cpp:

    Qt Code:
    1. MyClass::MyClass() {
    2. myOtherClass = new MyOtherClass();
    3.  
    4. MyOtherClass myOtherClass2;
    5.  
    6. QString myString = "Hello";
    7. }
    To copy to clipboard, switch view to plain text mode 

    As you can see this is quite newbie-easy stuff but where can I learn about this in an easy way?

    Thanks really much
    Last edited by wysota; 14th September 2010 at 21:11.

Similar Threads

  1. QEvent memory management
    By staser12 in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2010, 08:41
  2. QStackedWidget and memory management
    By martinn in forum Newbie
    Replies: 14
    Last Post: 8th April 2010, 00:14
  3. Memory Management Reg
    By BalaQT in forum Newbie
    Replies: 10
    Last Post: 4th February 2010, 12:43
  4. Memory management
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:48
  5. Memory management in QT
    By Gayathri in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2006, 07:21

Tags for this Thread

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.