Initial Memory Usage: 347816
Pre-Assignment Memory Usage: 347816
Post-Assignment Memory Usage: 1171112
Post-Unset Memory Usage: 1171112
Pre-Assignment Memory Usage: 1171112
Post-Assignment Memory Usage: 1171112
Post-Unset Memory Usage: 1171112
Pre-Assignment Memory Usage: 1171112
Post-Assignment Memory Usage: 1171112
Post-Unset Memory Usage: 1171112
Final Memory Usage: 1171112
Peak Memory Usage: 1994408
<?php
/* Try calling this script with ?unset=1 to see what happens when you unset the
* variable at the end
*
* paul reinheimer
* <firstname>@preinheimer.com
* http://blog.preinheimer.com/
*/
loopOverStuff();
highlight_file(__FILE__);
function loopOverStuff()
{
$var = null;
echo "Initial Memory Usage: " . memory_get_usage() . "<br>\n";
for($i = 0; $i < 3; $i++)
{
echo "Pre-Assignment Memory Usage: " . memory_get_usage() . "<br>\n";
$var = getData();
/* Do stuff here?
*/
echo "Post-Assignment Memory Usage: " . memory_get_usage() . "<br>\n";
if (isset($_GET['unset']))
{
unset($var);
}
echo "Post-Unset Memory Usage: " . memory_get_usage() . "<br>\n";
}
echo "Final Memory Usage: " . memory_get_usage() . "<br>\n";
echo "<b>Peak Memory Usage: " . memory_get_peak_usage() . "</b><br>\n";
}
function getData()
{
$a = str_repeat("This string is exactly 40 characters long", 20000);
return $a;
}