Bug #70459 [NEW]: memory_get_usage(true) returns wrong result

From: Date: Tue, 08 Sep 2015 10:23:34 +0000
Subject: Bug #70459 [NEW]: memory_get_usage(true) returns wrong result
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195870@lists.php.net to get a copy of this message
From: a dot schilder at gmx dot de Operating system: Windows 7 Pro PHP version: 7.0.0RC2 Package: Unknown/Other Function Bug Type: Bug Bug description:memory_get_usage(true) returns wrong result Description: ------------ I did some memory tests to compare PHP 7.0.0RC2 (TS, 64bit) with 5.x versions and realized a strange behavior when using memory_get_usage() with $real_usage set to TRUE. I did a first call of memory_get_usage(true), produced some data and did a second call of memory_get_usage(true), before using the data. Then I compared the logged memory consumption. In the example below I got a memory difference of about 78 MB when calling the script the first time, the next time I called the script I got about the half of this value, and further calls reduced it more and more until I got to 0 bytes between the first and second call of memory_get_usage(true). After a restart of the web server (Apache 2.4) I get the same behavior again. NOTE: $real_usage set to FALSE works as expected. Test script: --------------- <?php $oldMem = memory_get_usage(true); $array = array(); for ($i=1; $i <= 10000; $i++) { $array[$i] = range(1, 96); } $newMem = memory_get_usage(true); echo "Array size: " . count($array) . "<br>"; echo "Memory consumption BEFORE: " . $oldMem . "<br>"; echo "Memory consumption AFTER: " . $newMem . "<br>"; Expected result: ---------------- Result of the first 10 calls after the restart of the web server: Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Actual result: -------------- Result of the first 10 calls after the restart of the web server: Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 44040192 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 23068672 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 12582912 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 8388608 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 6291456 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 2097152 -- Edit bug report at https://bugs.php.net/bug.php?id=70459&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70459&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70459&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70459&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70459&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70459&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70459&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70459&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70459&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70459&r=support Expected behavior: https://bugs.php.net/fix.php?id=70459&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70459&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70459&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70459&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70459&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70459&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70459&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70459&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70459&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70459&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70459&r=mysqlcfg

« previous php.bugs (#195870) next »