\n";
$idmap = array();
$rows2 = array("_1" => array(), "_2" => array(), "_3" => array(), "_4" => array(), "_5" => array(), "_6" => array(), "_7" => array());
for ($x = 0; $x < 5000; $x++)
{
$idmap[$x] = array("test1");
$row2 = array("A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.", $x);
$options = array();
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
$row2[] = implode(" | ", $options);
$rows2["_6"][] = $row2;
}
// About 10MB RAM here with real-world data (the above is about 8MB with the test data - close enough?).
echo memory_get_usage(true) . "
\n";
$rows = array();
foreach ($rows2 as $key => $rows3)
{
foreach ($rows3 as $num => $row)
{
// This occasionally (i.e. randomly) leaks memory like crazy in here (> 128MB),
// despite the exact same data being passed in on the URL *AND* the exact same data in $rows2.
$row[1] = htmlspecialchars(implode(", ", $idmap[$row[1]]));
$rows[] = $row;
// Even weirder, adding a simple if-statement here that does absolutely nothing causes the leak to disappear...
//if ($_SERVER["REMOTE_ADDR"] != "")
//{
//}
echo memory_get_usage(true) . "
\n";
}
}
// About 20MB RAM here with real-world data...whenever the foreach() code above doesn't run wild.
echo memory_get_usage(true) . "
\n";
echo "Peak: " . memory_get_peak_usage(true) . "
\n";
?>