Created
October 24, 2010 23:58
-
-
Save akkunchoi/644171 to your computer and use it in GitHub Desktop.
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 | |
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