Bug #76520 [NEW]: Object creation leaks memory when executed over HTTP
| From: | tom dot denbraber at moxio dot com | Date: | Fri, 22 Jun 2018 13:14:56 +0000 |
| Subject: | Bug #76520 [NEW]: Object creation leaks memory when executed over HTTP | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215857@lists.php.net to get a copy of this message | ||
From: tom dot denbraber at moxio dot com
Operating system: Debian
PHP version: 7.2.7
Package: *Web Server problem
Bug Type: Bug
Bug description:Object creation leaks memory when executed over HTTP
Description:
------------
When creating a large amount of objects without storing them, the memory
usage keeps increasing, but only when the script is executed as an HTTP
request.
When executed over the CLI, the behaviour is as expected: the memory
usage is stable then.
The issue can be reproduced using the php:7.2.x-apache-stretch Docker
images and the script below.
The problem does not occur everytime you run the script: most of the
times, the first request after you boot the container will not show the
problem, but each following request does.
The problem is introduced in PHP 7.2: earlier versions of PHP do not
show this problem.
Creating arrays or scalars instead of objects works as it should and
does not retain memory.
Wrapping the loop in a function, to trigger a cleanup after the function
has executed does not help.
Test script:
---------------
<?php
$memory = memory_get_usage();
printf("before iterating, memory %d\n", $memory);
for($i = 0; $i < 1000000; $i++) {
if (($new_memory = memory_get_usage()) > $memory) {
$memory = $new_memory;
printf("iteration %d, memory %d\n", $i, $memory);
}
new \stdClass();
}
printf("after iterating, memory %d\n", memory_get_usage());
Expected result:
----------------
before iterating, memory 385728
iteration 0, memory 385760
after iterating, memory 385760
(obtained by running the script over the CLI in the Docker container)
Actual result:
--------------
before iterating, memory 378928
iteration 0, memory 379040
iteration 1024, memory 387232
iteration 2048, memory 403616
iteration 4096, memory 436384
iteration 8192, memory 501920
iteration 16384, memory 632992
iteration 32768, memory 895136
iteration 65536, memory 1419424
iteration 131072, memory 2468024
iteration 262144, memory 4565176
iteration 524288, memory 8759480
after iterating, memory 8759480
As you can see, the script goes from around 370 KB to using over 8 MB.
(obtained by running the script over HTTP)
--
Edit bug report at https://bugs.php.net/bug.php?id=76520&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76520&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76520&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76520&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76520&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76520&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76520&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76520&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76520&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76520&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76520&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76520&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76520&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76520&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76520&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76520&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76520&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76520&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76520&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76520&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76520&r=mysqlcfg