Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » Memory usage and refcount [RSS Feed]

#1 Jan. 5, 2011 17:31:37

Patrick A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Memory usage and refcount


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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » Memory usage and refcount [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support