I am writing some php scripts that deal with a lot of data but in chunks at a time within functions. kind of like this:
function part1(){
$data = getLargeArray();
$evenBigger = array();
foreach($data as $piece){
$evenBigger[$piece['part1']][$piece['part2']][] = ohGodMoreData();
}
//...manipulate $evenBigger more and more
return true;
}
part1();
part2();
//...etc
I am concerned about the memory usage of my functions. Not that they are terribly burdensome, but I fear that if the memory is not freed it might be. I know php frees all of its memory at the end of each script, but I also don't want to run 4 or 5 different scripts.
When I move onto part2();
is the memory freed from part1();
?
Should I manually unset the variables that take up so much space such as $data
and $evenBigger
or trust that php will do this for me when the function ends?
Alternatively:
-Is there a better way to let go of that memory?
-Any way to test such a thing?
-Any tips for better resource management?