I am learning memory management in C++ and I don\'t get the why only some of the destructors are called when leaving scope. In the code below, only obj1 destructor is called
First of all you should use delete
operator to destrory an object and not call its destructor directtly. Secondly, by doing new
you are telling the compiler that you dont want to delete the object when it goes out of the scope. In such case you need to explictly fo delete objj2;
to delete the object.