Skip to content

Instantly share code, notes, and snippets.

@AstDerek
Created April 6, 2013 00:58
Show Gist options
  • Save AstDerek/5323794 to your computer and use it in GitHub Desktop.
Save AstDerek/5323794 to your computer and use it in GitHub Desktop.
<style>
iframe { border:none;border-bottom:1px solid #ccc;width:100%;height:250px; }
body, * { font-family:Consolas,"Lucida Console","Lucida Typewritter","Courier New",Courier,monospace; }
</style>
<?php
class FOO {
public $f;
}
class BAR {
public $f;
}
$memory = 0;
$increases = 0;
gc_enable();
if (isset($_REQUEST['test'])) {
for ($n=1;$n<1000000 && $increases < 40 && $memory < (24 * 1024 * 1024);$n++) {
$a = new FOO();
$b = new BAR();
$a->f = $b;
$b->f = $a;
$current = memory_get_usage(true);
if ($current != $memory) {
$memory = $current;
$increases++;
print "Memory usage: " . number_format($memory) . " bytes at cycle $n<br>";
}
if (isset($_REQUEST['unset-all'])) {
unset($a->f);
unset($b->f);
}
if (isset($_REQUEST['unset']) || isset($_REQUEST['unset-all'])) {
unset($a);
unset($b);
}
}
echo "Total cycles: <strong>$n</strong><br>";
echo "Total garbage collection cycles: " . gc_collect_cycles();
}
else {
?>
<h2>No unset</h2>
<iframe src="test.php?test"></iframe>
<h2>Unset variables</h2>
<iframe src="test.php?test&amp;unset"></iframe>
<h2>Unset variables and references</h2>
<iframe src="test.php?test&amp;unset-all"></iframe>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment