|
![](/i/fill.gif) |
Orchid Win7 v1 <voi### [at] dev null> wrote:
> To be clear... I only need to do explicit deallocation if I've done
> explicit allocation in the first place, right?
Every 'new' must have a correspondent 'delete'. If you don't write 'new'
then you don't have to worry about any deletes either.
Of course the exception to this is if you are using a smart pointer like
std::shared_ptr or std::unique_ptr, in which case you do write 'new',
but let the smart pointer do the 'delete' for you.
If you really need to explicitly allocate memory, then it's usually a
good idea to use such a smart pointer, because they will make sure that
they will delete the object when the last smart pointer to it dies, and
delete it only once.
The thing is, even if you have written one 'new' and one 'delete' in your
code, the object might be being deleted more than once. This is because of
the wonderful thing in C++ that is copying and assigning of classes.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |