The process of removing unused scalars, arrays and objects is called garbage collection.
PHP's GC is based on reference counters. As soon as there is no more reference to a zval (internal structure storing variables), it may be removed by the garbage collector.
A nice introduction to reference counting and garbage collection is located here.
This basic understanding is important if you e.g. create another reference to the same zval (in this case your object):
$myHedgehog = new Hedgehog();
$yourHedgehog = $myHedgehog;
$myHedgehog = new Hedgehog();
In this case, the old Hedgehog object will stay and $yourHadgehog
will still point to it.
More confusing even when an object references itself:
$myHedgehog = new Hedgehog();
$myHedgehog->father = $myHedgehog;
unset($myHedgehog);
In this case, you will lose access to the Hedgehog object because no more symbol points to it, but since there still is a reference to it, the garbage collector will not delete it.
This also applies to an array that has a reference to itself as member:
$myArray = array();
$myArray['somekey'] =& $myArray;
unset($myArray);
Note the &
operator that will store a reference to $myArray
rather than copy the array.