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 and/or 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 (or destroy) my objects at all? Will that be a problem to memory?
MyClass.h
class MyClass
{
public:
MyClass();
~MyClass();
MyOtherClass *myOtherClass;
};
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?