Effective reading notes

1 About delete pointer

  • New and delete need to be used together, otherwise it will cause memory leaks.
  • To delete a single object, use delete p; to delete the entire group of objects, use delete [] p;
  • Deleting a pointer with an unallocated address will cause the program to crash;
  • It is safe to delete a null pointer
  • To configure the memory for the pointer new in the constructor, it needs to be deleted in the destructor.

Article 6 Essentials

For pointers, either they point to valid memory or null. In this way, you can safely delete the pointer in the destructor. When the pointer is defined, the initial value can be set to NULL or an effective address.

The difference between QT destruction

  • QT maintains a parent-child number for all objects, and automatically calls the destructor of the child object when the parent object is destructed.

Guess you like

Origin blog.csdn.net/u013894391/article/details/101235601