From: robin dot kunde at recoursive dot com
Operating system: Ubuntu 15.04, OSX 10.10.4
PHP version: 7.0.0beta1
Package: Performance problem
Bug Type: Bug
Bug description:Real memory usage doesn't decrease
Description:
------------
PHP 7b1 doesn't appear to be reclaiming freed memory correctly. This
problem only affects real usage as reported by memory_get_usage(true).
Usage as reported by memory_get_usage(false) behaves as expected.
The problem appears to be related to allocation of strings, the use of
stdclass, and/or multidimensional array. I don't believe PHP is actually
leaking memory, since usage is not continuously increasing. It just
appear that certain actions prevent real usage from decreasing again
after variables are nulled out or leave scope. The test script gist I
posted can demonstrates the problem better than I can explain it.
This problem still occurs with the master git branch as of 7/17.
Test script:
---------------
https://gist.github.com/robinkunde/68f3d442aa294550ab15
Expected result:
----------------
PHP 5.6.11
Assembling 5M string
Real: 0.50, Malloc: 0.25
Storing 1M bools
Real: 0.75, Malloc: 0.25
Real: 1.00, Malloc: 0.25
Real: 1.00, Malloc: 0.25
Storing 1M ints
Real: 1.25, Malloc: 0.25
Real: 1.25, Malloc: 0.25
Real: 1.50, Malloc: 0.25
Storing 1M stringyfied ints
Real: 1.50, Malloc: 0.25
Real: 1.75, Malloc: 0.25
Real: 1.75, Malloc: 0.25
Storing 1M stringyfied ints with stringyfied int keys
Real: 1.75, Malloc: 0.25
Real: 1.75, Malloc: 0.25
Real: 1.75, Malloc: 0.25
Storing 1M empty strings
Real: 1.75, Malloc: 0.25
Real: 2.00, Malloc: 0.25
Real: 2.00, Malloc: 0.25
Storing 1M hellos
Real: 2.00, Malloc: 0.25
Real: 2.25, Malloc: 0.25
Real: 2.00, Malloc: 0.25
Storing 1M hellos with stringyfied int keys
Real: 2.00, Malloc: 0.25
Storing 1M empty arrays
Real: 1.50, Malloc: 0.25
Real: 2.00, Malloc: 0.25
Real: 2.00, Malloc: 0.25
Storing 1M arrays with empty strings
Real: 2.00, Malloc: 0.25
Real: 2.50, Malloc: 0.25
Real: 2.50, Malloc: 0.25
Storing 1M arrays with hello
Real: 2.50, Malloc: 0.25
Real: 2.75, Malloc: 0.25
Real: 2.75, Malloc: 0.25
Final Usage
Real: 2.75, Malloc: 0.25
Real peak: 436.00, Malloc peak: 435.50
Actual result:
--------------
PHP 7.0.0b1
Assembling 5M string
Real: 4.00, Malloc: 0.36
Storing 1M bools
Real: 4.00, Malloc: 0.36
Real: 32.00, Malloc: 0.36
Real: 32.00, Malloc: 0.36
Storing 1M ints
Real: 32.00, Malloc: 0.36
Real: 32.00, Malloc: 0.36
Real: 32.00, Malloc: 0.36
Storing 1M stringyfied ints
Real: 32.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Storing 1M stringyfied ints with stringyfied int keys
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Storing 1M empty strings
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Storing 1M hellos
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Real: 62.00, Malloc: 0.36
Storing 1M hellos with stringyfied int keys
Real: 62.00, Malloc: 0.36
Storing 1M empty arrays
Real: 116.00, Malloc: 0.36
Real: 116.00, Malloc: 0.36
Real: 116.00, Malloc: 0.36
Storing 1M arrays with empty strings
Real: 422.00, Malloc: 0.36
Real: 422.00, Malloc: 0.36
Real: 422.00, Malloc: 0.36
Storing 1M arrays with hello
Real: 422.00, Malloc: 0.36
Real: 422.00, Malloc: 0.36
Real: 422.00, Malloc: 0.36
Final Usage
Real: 422.00, Malloc: 0.36
Real peak: 476.00, Malloc peak: 425.46
--
Edit bug report at https://bugs.php.net/bug.php?id=70098&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70098&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70098&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70098&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70098&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70098&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70098&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70098&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70098&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70098&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70098&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70098&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70098&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70098&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70098&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70098&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70098&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70098&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70098&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70098&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70098&r=mysqlcfg