|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74174 Memory allocation problem
Submitted: 2017-02-27 12:31 UTC Modified: 2017-03-12 04:52 UTC
From: enleury at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: Performance problem
PHP Version: 7.1.2 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: enleury at gmail dot com
New email:
PHP Version: OS:


 [2017-02-27 12:31 UTC] enleury at gmail dot com
Memory is not freed after return from the method. Looks like a heap defragmentation issue (, but it works fine on 5.x branches.

Online test script for 5.x and 7.x branches:

Test script:

function create_docs($amount)
    $documents = [];

    for ($i = 0; $i < $amount; $i++) {
        $documents[] = ['a' => $i];

echo memory_get_usage(true), PHP_EOL;

echo memory_get_usage(true), PHP_EOL;

echo memory_get_usage(true), PHP_EOL;

echo memory_get_usage(true), PHP_EOL;

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-27 14:23 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2017-02-27 22:16 UTC]
-Status: Assigned +Status: Feedback
 [2017-02-27 22:16 UTC]
This is not a bug.
If you compare peak memory usage, PHP-7 wins.

PHP-7 just manages memory differently.
It allocates system memory by bigger chunks (2MB) and doesn't return free chunks back to system immediately, assuming that script may request the same amount again.
 [2017-02-28 07:59 UTC] enleury at gmail dot com
Thank you for clarification. Is gc_mem_caches() the only way to free up chunks?
 [2017-02-28 10:23 UTC]
yes. I forgot, we exposed MM GC to user-level :)
Actually, even this function may keep one (or maybe few) unused chunk(s) cached.

Zend MM was highly tuned especially for typical real-life usage, but any suggestions for improvement are welcome.
 [2017-03-12 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2017-03-12 04:52 UTC]
-Status: No Feedback +Status: Not a bug
 [2017-03-12 04:52 UTC]
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 01:01:32 2024 UTC