Although it is mentioned in the manual, you have to be careful when using output buffering in big cycles (such as mass mail sending scripts), because ob_clean() actually does not free any memory, and with each iteration the amount of memory allocated from your script will increase significantly. Instead of calling ob_clean() at the end of the cycle, you have to either use ob_get_clean(), which is a combination of ob_get_contents() and ob_end_clean(), or just ob_end_clean() to free the memory. Try the following test to see the difference:
<?php
for ($i=0; $i<10; $i++) {
ob_start();
echo "This is iteration $i: ";
$buf = ob_get_clean();
echo $buf;
echo memory_get_usage()."\n";
}
?>