Explanation of the garbage collection mechanism of php memory management (Figure)

Source: Internet
Author: User
Each php variable exists in a zval variable container. in addition to the type and value of the variable, the container also determines whether is_ref is a reference. each php variable exists in a zval variable container, besides the types and values of variables, the container also determines whether is_ref is referenced.

There is also a refcount reference count. when a variable is assigned to another variable, the number of references is increased. when the variable is unset or left

In its scope, the reference count is reduced by 1, and when the reference count is reduced to 0, the memory is recycled. However, such a mechanism has memory during cyclic reference.

Leakage.

For example, when an array is regarded as an array element

Memory cannot be recycled.

To solve this problem, the gc mechanism is introduced after php5.3. Specifically, a root buffer is created to add suspicious zval variable containers

With the buffer, the default value is 1000. you can set it. if it is full, clear it based on the recycle algorithm mechanism.

The above is a detailed description of the garbage collection mechanism of php memory management (figure). For more information, see other related articles in the first PHP community!

Related Article

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.