Garbage Collection
Garbage collection is a PHP mechanism that checks memory and frees it when it needs to store new values.
PHP allocates memory as it needs, when variables and objects are created in the code. Sometimes, those variables are destroyed, using explicit unset() calls, or implicitly, when leaving a method or destroying an object.
To speed up the process, PHP postpones memory cleaning until the end of the application, or when it reaches some internal threshold. Then, it reviews all the currently allocated variables, and when they are not used anymore, that is when the reference counter is down to 0, it removes them.
As garbage collection requires pausing the execution, PHP only runs it on-demand, via gc_collect_cycles() calls, or once every ten thousand objects to clear.
Garbage collection is needed to handle circular reference: objects that mutually reference each other, and which requires some processing to identify as dead data.
<?php
// Explicit Garbage Collection
gc_collect_cycles();
// implicit garbage collection
// well,... difficult to illustrate, right?
?>