Edit report at https://bugs.php.net/bug.php?id=65340&edit=1
ID: 65340 Comment by: vitalif at mail dot ru Reported by: vitalif at mail dot ru Summary: Memory leak when using magic __set ? Status: Open Type: Bug Package: Class/Object related Operating System: Linux PHP Version: 5.5.1 Block user comment: N Private report: N New Comment: I don't think bug #48197 is related to this issue... There are no memory leaks. I.e. extra alloc done by __call in that bug is freed without problem (if you remove "$b[$i] =" and just throw away the value after each call). And here I describe that an identical object takes twice more memory if you write in its array property using __set. Previous Comments: ------------------------------------------------------------------------ [2013-07-26 01:51:01] fel...@php.net See bug #48197 ------------------------------------------------------------------------ [2013-07-25 21:38:37] vitalif at mail dot ru 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 this bug report at https://bugs.php.net/bug.php?id=65340&edit=1