Garbage Collection Flashcards

1
Q

What is a zval?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In a zval, if refcount is 1, then is_ref is…

A

…always FALSE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When do zvals get destroyed?

A

When their refcount reaches zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When does a refcount get decremented?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you turn the garbage collecting mechanism on and off?

A

By calling gc_enable() and gc_disable() respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does garbage collection affect performance?

A

Reduced memory usage and run-time slowdowns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly