Memory management in Qt?

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-03-22T11:17:03Z Indexed on 2010/03/22 11:21 UTC
Read the original article Hit count: 360

Filed under:
|
|

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:

class MyClass
{

public:
    MyClass();
    ~MyClass();
    MyOtherClass *myOtherClass;
};

in MyClass.cpp:

MyClass::MyClass() {
    myOtherClass = new MyOtherClass();

    MyOtherClass myOtherClass2;

    QString myString = "Hello";
}

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

Thanks really much

© Stack Overflow or respective owner

Related posts about qt

Related posts about memory