Last active
December 28, 2015 21:09
-
-
Save Xerkus/7562464 to your computer and use it in GitHub Desktop.
Simple test to prove garbage collector does not detect circular reference if SPL object is used.
This file contains 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
<?php | |
gc_enable(); | |
class test | |
{ | |
public $spl; | |
public function __construct() | |
{ | |
$this->spl = new SplPriorityQueue(); | |
$this->spl->insert($this, 1); | |
} | |
} | |
$i = 0; | |
while($i < 50000) { | |
$test = new test(); | |
unset($test); | |
gc_collect_cycles(); | |
echo sprintf('%1$04d: ', $i) . number_format(memory_get_usage()) . " B\n"; | |
$i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment