More about programming styleΒΆ
In the course material of round 4, we discussed programming style rather extensively. However, at that point, we had not considered dynamic memory management at all, and thus, it was not possible to pay attention to programming style related to that topic, either.
Rules for programming style concerning dynamic memory management that are used on this course, are listed above:
- The object or module that have allocated memory, is principally responsible to deallocate the memory, too.
- If a
delete
command is targeted to an assignable pointer variable, it will be assigned to the valuenullptr
immediately after thedelete
command. - A destructor must deallocate all the resources that have been allocated by the object in question.
- Unnecessary copy constructor and assignment operator must
(on this course)
be disabled by introducing them in the
public
part of the class and using the worddelete
, as explained in the course material at the end of round 9. - If there is no good reason for using normal and smart pointers mixed, then do not do so.
The next round introduces graphical user interfaces.
Memory management related to them are considered in the section
about widgets and especially in the context of parent-child mechanism.
This mechanism makes memory management simpler and decreases the
need for delete
command.
That command is still needed if an object has been created with the
new
command and if the object has no parent.