Created
July 2, 2013 09:44
-
-
Save anonymous/5908019 to your computer and use it in GitHub Desktop.
About cyclic objects.
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
$ php test.php | |
Array | |
( | |
[a] => 1 | |
[b] => 1 | |
) | |
Array | |
( | |
[a] => 1 | |
[b] => 1 | |
) | |
Array | |
( | |
[a] => 1 | |
[b] => 1 | |
) | |
2 cyclic objects freed | |
Array | |
( | |
) |
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
<?php | |
class a {} | |
class b {} | |
$a = new a; | |
$b = new b; | |
print_r(get_objects_count()); | |
// Create circular deps | |
$a->b = $b; | |
$b->a = $a; | |
print_r(get_objects_count()); | |
// Destroying objects | |
unset($a, $b); | |
print_r(get_objects_count()); | |
// Forces collection of any existing garbage cycles | |
echo gc_collect_cycles(), " cyclic objects freed\n"; | |
print_r(get_objects_count()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment