Created
April 6, 2013 00:58
-
-
Save AstDerek/5323794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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&unset"></iframe> | |
<h2>Unset variables and references</h2> | |
<iframe src="test.php?test&unset-all"></iframe> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment