PHP features-garbage collection mechanism 1-basic knowledge of reference counting

Source: Internet
Author: User
Each php variable exists in a variable container named & quot; zval & quot. A zval variable container not only contains the type and value of the variable, but also contains two bytes of additional information. Each php variable is stored in a variable container named "zval. A zval variable container not only contains the type and value of the variable, but also contains two bytes of additional information. The first is "is_ref", which is a bool value to identify whether the variable belongs to the reference set ). With this byte, the php engine can distinguish between common variables and reference variables. because php allows users to use & to use custom references, the zval variable container also has an internal reference counting mechanism, to optimize memory usage. The second extra byte is "refcount", used to indicate the number of variables (also known as symbol) pointing to the zval variable container. All symbols exist in a symbol table. each symbol has a scope, and the primary scripts (for example, scripts requested by a browser) and each function or method have a scope.
When a variable is assigned a constant value, a zval variable container is generated, as shown in the following example:

Example #1 create a new zval container

 

The above is the garbage collection mechanism of PHP features 1-reference the basic knowledge of counting content. For more information, please follow the PHP Chinese network (www.php1.cn )!

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.