Firstly, I think you should describe exactly what you mean by "at the end of a function", do you mean at the end of a function call or ...?
PHP stores the function in memory as a construct, if you are not executable code, then when the function is executed, depending on what the function actually performs, memory is allocated.
For example, if I had the following function:
function test() { $data = array(); for($i = 0; $i < 10000; $i++) { $data[] = array('one','two','three','four','five','six',); } }
the function is called and a memory reference is created for the array, each time you repeat the loop, the memory increases.
Then the function ends, but if you notice that the data is not returned, this is due to the fact that the local variable is available only for this current area, there it will no longer be used, and the garbage collector will clear the memory.
So yes, it clears the allocated memory at the end of the function call.
A quick tip (does not apply to objects in PHP 5).
you can pass data by links, so your only modification of the same allocated memory, regardless of function,
eg:
$data = str_repeat("a",5000); function minip(&$data) { $_data &= $data; $_data = ''; }
im passes the point in $data to a new variable that just points to the old one, so you can transfer data without making the garbage collector more resources.