From: vitalif at mail dot ru
Operating system: Linux
PHP version: 5.5.1
Package: Class/Object related
Bug Type: Bug
Bug description:Memory leak when using magic __set ?
Description:
------------
Hello!
I've discovered that when setting properties via __set() the object takes
much more memory than it should. It's reproducible at least on PHP 5.5 and
5.4. Is it a memory leak?
Test script:
---------------
<?php
// Memory leak somewhere around __set?
class A
{
var $data = array();
function __get($k)
{
return $this->data[$k];
}
function __set($k, $v)
{
return $this->data[$k] = $v;
}
}
$b = new A();
for ($i = 0; $i < 500000; $i++)
$b->{"a$i"} = 'abc';
var_dump(memory_get_usage()); // int(78318488) - why so big?
$c = clone $b;
unset($b);
var_dump(memory_get_usage()); // int(42220972) - OK
unset($c);
$b = new A();
for ($i = 0; $i < 500000; $i++)
$b->__set("a$i", 'abc');
var_dump(memory_get_usage()); // int(42221492) - OK
Expected result:
----------------
I expect roughly the same memory usage at all three points. Like:
int(42220972)
int(42220972)
int(42221492)
Actual result:
--------------
The first value is much bigger:
int(78318488)
int(42220972)
int(42221492)
--
Edit bug report at https://bugs.php.net/bug.php?id=65340&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65340&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65340&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65340&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65340&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65340&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65340&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65340&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65340&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65340&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65340&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65340&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65340&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65340&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65340&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65340&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65340&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65340&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65340&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65340&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65340&r=mysqlcfg