C ++ common memory errors

Source: Internet
Author: User

1. failed to realize Memory Allocation

After applying for memory allocation, use it without checking whether the memory allocation is successful.

2. Although the memory has been allocated successfully, it has not been initialized and is used.

This error is mainly because many people think that the memory I just allocated is already initialized, or it is all 0 by default.

Therefore, Initialization is required after the memory is allocated.

3. The memory allocation is successful and initialized. However, the memory usage is out of bounds. In this case, it is not easy to make a mistake.

 

4. Memory not released

Who must apply for the release of the memory? The memory is applied for in the function you write. Remember to release the memory when the function ends. (Of course, this method is used by others. And if it is called multiple times, it takes a long time to call

If the number is more than one, the game is over ).

 

5. The memory is released, but it is still used.

This problem is mainly because the pointer is not assigned null after the delete operation, which makes the pointer A wild pointer.

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.