Skip to content

Instantly share code, notes, and snippets.

@akkunchoi
Created October 24, 2010 23:58
Show Gist options
  • Save akkunchoi/644171 to your computer and use it in GitHub Desktop.
Save akkunchoi/644171 to your computer and use it in GitHub Desktop.
<?php
class A{
public $obj;
public function __destruct() {
unset($this->obj);
}
}
class B{
public $obj;
public function __destruct() {
unset($this->obj);
}
}
function getRecursiveReferenceObj(){
$a = new A;
$b = new B;
$a->obj = $b;
$b->obj = $a;
return $a;
}
foreach (range(1, 100) as $i){
$a = getRecursiveReferenceObj();
// unset($a); // BAD: unset doesn't call __destruct
// $a->__destruct(); // GOOD
var_dump(memory_get_usage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment