New, delete, and new [] Delete []

Source: Internet
Author: User
We all know that new and delete, new [] and delete [] must be used in pairs, but not everyone knows what the difference between Delete and delete.
Some people may say that delete is not the object to be deleted, but delete is the object to be deleted. This statement is only half right.
Indeed, delete [] is used to release arrays. What if I use Delete to release arrays? There are two cases:
1. Delete basic data type array
In this case, the effects of Delete and delete [] are the same, and the Array Memory is released.
2. Delete custom data type array
In this case, delete is used to release the Array Memory, but only the destructor of the first object of the array is called. Delete [] not only releases the memory, the destructor of each array object is also called.

The difference between Delete and delete [] is whether to call the destructor of each array object in the array. Therefore, we still use the new, delete, new [], and delete [] pairs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.