Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) delete

 

Keyword to release dynamically allocated memory (allocated by the keyword new).

 

 

 

MyClass * myClass = new MyClass;

//Do stuff on myClass

delete myClass;

 

 

Prefer to use smart pointers [1] . If you do so, you rarely ever need to use delete.

 

Be aware that it is valid to delete a pointer-to-const.

 

References

  • Herb Sutter and Andrei Alexandrescu . C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 13: 'Ensure resources are owned by objects. Use explicit RAII and smart pointers.

     

     

    Go back to Richel Bilderbeek's C++ page.

    Go back to Richel Bilderbeek's homepage.