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!