|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-06-22 14:00 UTC] nikic@php.net
-Status: Open
+Status: Verified
[2018-06-22 14:00 UTC] nikic@php.net
[2018-06-22 14:12 UTC] nikic@php.net
-Status: Verified
+Status: Analyzed
[2018-06-22 14:12 UTC] nikic@php.net
[2018-06-22 14:23 UTC] nikic@php.net
[2018-06-22 14:23 UTC] nikic@php.net
-Status: Analyzed
+Status: Closed
[2018-06-22 14:33 UTC] nikic@php.net
-Assigned To:
+Assigned To: nikic
[2018-06-22 14:33 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 08:00:01 2025 UTC |
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)