Initial Memory Usage: 227984
Pre-Assignment Memory Usage: 228032
Post-Assignment Memory Usage: 1048104
Post-Unset Memory Usage: 1048104
Pre-Assignment Memory Usage: 1048104
Post-Assignment Memory Usage: 1048088
Post-Unset Memory Usage: 1048088
Pre-Assignment Memory Usage: 1048088
Post-Assignment Memory Usage: 1048088
Post-Unset Memory Usage: 1048088
Final Memory Usage: 1048088
Peak Memory Usage: 1870704
<?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;
}