Skip to content

Instantly share code, notes, and snippets.

@Xerkus
Last active December 28, 2015 21:09
Show Gist options
  • Save Xerkus/7562464 to your computer and use it in GitHub Desktop.
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.
<?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