About Delete and delete[]

Source: Internet
Author: User

C + + tells us to use delete[] when reclaiming the memory space of a single object allocated with new and using Delete to reclaim the memory space of a set of objects allocated with new[].
About new[] and delete[], which are divided into two cases : (1) Allocate and reclaim space for basic data Types , and (2) allocate and reclaim space for custom types .
Basic types of objects do not have destructors, so it should be possible to reclaim the array space of basic types with delete and delete[] , but only with delete[] for an array of class objects.
So a simple use principle is: New and delete, new[] and delete[] corresponding to use.

Title: Use char* p = new char[100] To apply for a piece of memory, then use delete p to release, what's the problem?

There will be memory leaks.
There is no memory leak, but it is not recommended
Compile will be error, must use delete []p;
Compile no problem, run will crash directly

About Delete and delete[]

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.