My class has a member variable array, items. Periodically I reassign the array to be the value of another, temporary array, like this:
$temp = array(); $temp = new Object(); $temp = new Object(); $temp = new Object(); ... etc. $this->items = $temp;
So, could I have a memory leak? By reassigning the value of $this->temp to a new value, $temp, would all the items (the items are objects) originally in $this->temp still linger around, or would they be freed?
This will not cause a memory leak. $temp and $this->items are just references to the same array. Since PHP is a garbage collected language, the array will be deleted (garbage collected) when there are no more references to the array.
They will linger around for a little while, but in PHP they will be freed eventually by the garbage collector.