Memory usage and refcount
| From: | Patrick ALLAERT | Date: | Wed, 05 Jan 2011 17:30:15 +0000 |
| Subject: | Memory usage and refcount | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-51224@lists.php.net to get a copy of this message | ||
Hi,
While debugging some memory usage stuff I came across the fact that:
<?php
class foo {
// $x as a static *class* var
static $x = "foo";
static function def() {
return self::$x;
}
}
$x1 = foo::def();
$x2 = foo::def();
$x3 = foo::def();
$x4 = foo::def();
xdebug_debug_zval('x4');
?>
will display a refcount of 5 while:
<?php
class foo {
static function def() {
// $x as a static *function* var
static $x = "foo";
return $x;
}
}
$x1 = foo::def();
$x2 = foo::def();
$x3 = foo::def();
$x4 = foo::def();
xdebug_debug_zval('x4');
?>
will display a refcount of 1.
Can someone explain me why a real copy is made in the 2nd case?
Is this on purpose?
Regards,
--
Patrick Allaert
---
http://code.google.com/p/peclapm/ - Alternative PHP
Monitor