In PHP, you never have to worry about memory usage outside of your own realm. unset($obj)
will work fine in your case. Alternatively, you can simply leave the function you are in:
function f() { $obj = new ArrayObject();
And the data will be cleared just fine.
Managing PHP's internal memory is pretty simple: reference counting is stored for each piece of data, and if it is 0, then it is freed. If only the ArrayObject contains the object, then it has the value 1. When the ArrayObject is gone, refcount is 0, and the object will be deleted.
source share