As others have noted, if you use new , you will need delete . However, your real problem is conceptual. You are asking a good question for which new and delete are peripheral.
The usual use of destructors, over 99.5% of the time, should allow the compiler to automatically call them. (The exception is 0.5%, and we do not need to worry about it right now.)
Consider this piece of code:
int n = 5; { int m = 2; ++m; n *= m;
See how it works? The m destructor is automatically called when m reaches the end of its life, which (because m not done with new ) happens at the end of the block in which m is created.
Of course, m is int , so its destructor does nothing (or, if you want, m does not have a destructor). Other types that you define yourself, such as your account type, may have destructors. The destructor is automatically called against one object at a time when this single object, an instance of account , reaches the end of its life.
NEW & DELETE
So what does this have to do with new and delete ?
In my code snippet, I did not use new . Therefore, the lifetime of my object was controlled by the attached braces.
In the code snippet, you used new . Therefore, the lifetime of your object is controlled by your use of delete .
Of course, you forgot to use delete , so your object has never been destroyed (except, perhaps, when your entire program ends).
Others have noted that modern C ++ provides improved
new alternatives that you should use in most cases. You can read their answers for them. However, mechanically, itโs still very useful to understand what ordinary
new does and how
delete combines with it.
DESTROYERS MANAGEMENT GUIDE
You almost certainly should not worry about this, because cases where the destructor is started manually are rare and advanced. Basically, if you control the memory in which the object is stored (which you almost never do, but there are rare exceptions), then the compiler cannot say when to destroy, so you should say it when. See this for a typical esoteric example.