C + +: Memory management specification for address delivery and assignment operations

Source: Internet
Author: User

# C + +: Memory management specification for address delivery and assignment operations #

In order to ensure that the class instance can determine and effectively clear its own created memory consumption, while ensuring a low memory footprint, you should make the data inside the class as far as possible with reference delivery, for the externally passed-in object itself can use reference delivery, for external objects have a variety of data, such as other objects or fields that have been passed into the internal object, Method return value, you should use the copy value operation to get the data instead of reusing the reference.

With regard to the data referencing the object itself rather than the object, there is a correct data to ensure the validity of this. If the referenced object disappears first, it can clear its own memory, and if the referrer disappears first, it will not affect the memory management of the referenced object.

If you reference data from other objects, it is possible that objects that are referenced to the data will not be able to clean the memory properly, either externally or by referencing it internally. If the object of the referenced data disappears first, then its occupied address data is left behind and there is no chance of clearing it. This is the flaw in memory management and should be eliminated.

In other words, like inherited relationships, each object can have only one referrer. If there are multiple levels of objects, the top-level object can be referenced, not the top-level object, and cannot be referenced again.

C + +: Memory management specification for address delivery and assignment operations

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.