Garbage Collection Flashcards
What is a zval?
A container in which a PHP variable is stored. A zval container contains, besides the variable’s type and value, two additional bits of information. The first is called is_ref, and is a boolean value indicating whether or not the variable is part of a “reference set”. The second piece of additional information, called “refcount”, contains how many variable names (also called symbols) point to this one zval container.
In a zval, if refcount is 1, then is_ref is…
…always FALSE.
When do zvals get destroyed?
When their refcount reaches zero.
When does a refcount get decremented?
When any symbol linked to the variable container leaves the scope (e.g. when the function ends), or when unset() is called on a symbol.
How can you turn the garbage collecting mechanism on and off?
By calling gc_enable() and gc_disable() respectively.
How does garbage collection affect performance?
Reduced memory usage and run-time slowdowns.