Initial Memory Usage: 215776
Pre-Assignment Memory Usage: 215824
Post-Assignment Memory Usage: 1035880
Post-Unset Memory Usage: 1035880
Pre-Assignment Memory Usage: 1035880
Post-Assignment Memory Usage: 1035880
Post-Unset Memory Usage: 1035880
Pre-Assignment Memory Usage: 1035880
Post-Assignment Memory Usage: 1035880
Post-Unset Memory Usage: 1035880
Final Memory Usage: 1035880
Peak Memory Usage: 1856272
<?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;
}