Without laying it on too thick for johnjohn who is just starting it out. Calling "new" should be increadibly rare. As in if we are calling it, we are probably doing something wrong. There are a lot of old tutorials out there (even though in C++98 we should still be handrolling our own smart pointers since std containers are defective with std::auto_ptr). The following:in C++ -- if you call "new" to create something (like a "Class Object", raw pointer or similar) -- you will need to also call "delete" to later free the memory used by that resource.
- std::vector should contain and control lifespan of many elements (same with list/map/etc)
- std::unique_ptr (and std::make_unique) should contain and control lifespan of one element
So really we should never be controlling the owning pointer of an object directly in C++. Whereas in C, this is the norm (and necessary).
I would go so far as to say the only valid (and exception safe) use of new is "placement new". But honestly, this stuff isn't important at this point. Like I mentioned earlier, C++ has a lot of... cruft.