The garbage collection mechanism used before php5.3 is "reference count ".
The principle of "reference count" is that each memory object is allocated with a counter. When the memory object is referenced by a variable, the counter + 1; when the variable reference is removed, the counter-1; when the counter is 0, it indicates that the memory object is not used. The memory object is destroyed and garbage collection is completed.
There is a problem with "reference count", that is, when two or more objects reference each other to form a ring, the counter of the memory object will not be reduced to 0; this will cause memory leakage.
Now let's take a look at several operations related to PHP memory release:
1. & Symbol impact
Explicitly referencing a variable increases the reference count of the memory:
$ A = "something ";
$ B = & $;
At this time, unset ($ a), but there is still a reference of $ B pointing to the memory area, the memory will not be released.
2. Impact of unset Functions
Unset only disconnects a variable from A memory area, and calculates the reference count of the memory area-1, but is inside the loop body, for example, $ a = new (); unset ($ a); does not reduce the reference count of $ a to zero;
3. Impact on the null value operation of the variable;
$ A = null: directly empty the data structure pointed to by $ a and return the reference count to 0.
4. Impact of script execution completion
After the script is executed, all memory used in the script will be released, regardless of whether there is a reference ring.
So the above introduces so much memory-related things, but the memory is recycled by the PHP garbage collection process. Of course, you can also manually recycle the process like writing C and assign null values to the variables used. However, this will increase the complexity of the program, but it is generally not recommended for PHP. If, as mentioned in your Q & A, it is in the code that processes a large amount of code and runs for a long time, it is better to manually destroy some unused variables. You can also use functions such as memory_get_usage and memory_get_peak_usage to monitor memory usage.