Bug #79392 [NEW]: get_object_vars() memory leak
| From: | tomas914 at gmail dot com | Date: | Wed, 18 Mar 2020 12:01:03 +0000 |
| Subject: | Bug #79392 [NEW]: get_object_vars() memory leak | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-226148@lists.php.net to get a copy of this message | ||
From: tomas914 at gmail dot com
Operating system: Windows 10
PHP version: Irrelevant
Package: Performance problem
Bug Type: Bug
Bug description:get_object_vars() memory leak
Description:
------------
I'm developing an app which uses storage with fairly large amount of
objects that are created from unserialized cached data.
Objects properties are set by iterating through get_object_vars() which
causes extremely high memory usage.
Provided is reduced test case for reproducing this issue. The difference
between two create functions is only the amount of get_object_vars()
calls which leads me to conclusion it's a memory leak.
Results are:
Create(): Memory usage: 28.72MB
CreateWithLeak(): Memory usage: 95.1MB
Test script:
---------------
abstract class ObjectVarsCache
{
public static $vars = array();
}
class Test
{
public $a;
public $b;
public $c;
public $d;
public $e;
public $f;
public $g;
public $h;
public $i;
public $j;
public function CreateWithLeak()
{
$vars = get_object_vars($this);
}
public function Create()
{
$vars = &ObjectVarsCache::$vars;
if (!$vars)
$vars = get_object_vars($this);
}
}
$objects = array();
for ($i = 0; $i < 100000; ++$i)
{
$object = new Test;
//$object->Create(); // uncomment to compare
$object->CreateWithLeak();
$objects []= $object;
}
echo "Memory usage: ".round(memory_get_usage() / 1024 / 1024, 2)."MB,
Peak memory usage: ".round(memory_get_peak_usage() / 1024 / 1024,
2)."MB";
--
Edit bug report at https://bugs.php.net/bug.php?id=79392&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79392&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79392&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79392&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79392&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79392&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79392&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79392&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79392&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79392&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79392&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79392&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79392&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79392&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79392&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79392&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79392&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79392&r=mysqlcfg