PHP garbage collection mechanism is php5 after this thing, I would like to introduce to you about the PHP garbage collection mechanism Some understanding, I hope you have some help.
The garbage collection mechanism used before PHP 5.3 is a simple "reference count", that is, each memory object is assigned a counter, when the memory object is referenced by a variable, counter 1; When the variable reference is removed, the counter-1; when the counter = 0 o'clock indicates that the memory object is not being used, the memory object is destroyed. Garbage collection is complete.
The problem with reference counting is that when two or more objects reference each other to form a ring, the counter of the memory object is not reduced to 0; At this time, this set of memory objects is useless, but cannot be recycled, resulting in memory leaks;
php5.3 started with a new garbage collection mechanism, based on reference counting, a complex algorithm was implemented to detect the existence of reference rings in memory objects to avoid memory leaks.
PHP garbage collection mechanism