Use RAII types
This sample is licensed under the CC0 Public Domain Dedication.
Avoid manual memory management to improve safety and reduce bugs and memory leaks.
Every object created on lines 8–12 will internally manage some
dynamically allocated memory (allocated with the
They are all, however, implemented such that they deallocate that
memory when they are destroyed. This practice is known as RAII.
The user of these classes does not need to perform manual memory
management, reducing the risk of memory leaks and other bugs. In
fact, the use of
delete can be avoided entirely by
using these RAII types.