Bug #74174 [Com]: Memory allocation problem

From: Date: Tue, 28 Feb 2017 07:59:53 +0000
Subject: Bug #74174 [Com]: Memory allocation problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207602@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74174&edit=1

 ID:                 74174
 Comment by:         enleury at gmail dot com
 Reported by:        enleury at gmail dot com
 Summary:            Memory allocation problem
 Status:             Feedback
 Type:               Bug
 Package:            Performance problem
 Operating System:   Ubuntu
 PHP Version:        7.1.2
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for clarification. Is gc_mem_caches() the only way to free up chunks?


Previous Comments:
------------------------------------------------------------------------
[2017-02-27 22:16:07] dmitry@php.net

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-27 12:31:29] enleury at gmail dot com

Description:
------------
Memory is not freed after return from the method. Looks like a heap defragmentation issue
(https://bugs.php.net/bug.php?id=53669), but it works fine on 5.x branches.

Online test script for 5.x and 7.x branches: https://3v4l.org/2OVeU#output

Test script:
---------------
<?php

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

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

echo memory_get_usage(true), PHP_EOL;

create_docs(5000);
echo memory_get_usage(true), PHP_EOL;

create_docs(50000);
echo memory_get_usage(true), PHP_EOL;

create_docs(5000);
echo memory_get_usage(true), PHP_EOL;

Expected result:
----------------
262144
524288
524288
524288

Actual result:
--------------
2097152
4194304
20971520
20971520


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74174&edit=1


Thread (7 messages)

« previous php.bugs (#207602) next »