The PHP garbage collection mechanism is something that only exists after php5. Let me introduce some understandings about the PHP garbage collection mechanism. I hope it will be helpful to all students.
The garbage collection mechanism used before php 5.3 is a simple "reference counting", that is, each memory object is allocated a counter. When the memory object is referenced by a variable, the counter is 1; when the variable reference is removed, the counter is -1; When the counter = 0, it indicates that the memory object is not used, the memory object is destroyed, and the garbage collection is completed.
There is a problem with "reference counting", that is, when two or more objects refer to each other to form a ring, the counter of the memory object will not be reduced to 0; at this time, this group of memory objects is useless, but cannot be recycled. resulting in memory leaks;
Starting from php5.3, a new garbage collection mechanism has been used. Based on reference counting, a complex algorithm has been implemented to detect the existence of reference rings in memory objects to avoid memory leaks.