php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32689 memory leak
Submitted: 2005-04-13 01:10 UTC Modified: 2005-04-13 20:16 UTC
From: jerome at kingofsofa dot org Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.0.4 OS: linux
Private report: No CVE-ID: None
 [2005-04-13 01:10 UTC] jerome at kingofsofa dot org
Description:
------------
I think I have found a memory leak in php 4 and 5

depending on the size of the string concatenated to a variable a few bytes of memory are lost. See attached code.

I have noticed that if you replace echo "instance $i "... by a "smaller" sentence echo "i $i " then the leak is not there.

Since it has been there for a while I was wondering if this is actually an expected behavior. If so how should I do to avoid this.

This is part of a script running constantly and calling some trace function that end up doing an echo.

Reproduce code:
---------------
for( $i = 0; $i < 100 ; $i++ ) {
  echo "instance $i ".memory_get_usage()."\n";
}
echo "-------------------------------------------\n";
for( $i = 0; $i < 100 ; $i++ ) {
  echo "instance ";
  echo $i;
  echo " ".memory_get_usage()."\n";
}


Expected result:
----------------
Content-type: text/html
X-Powered-By: PHP/5.0.4

instance 0 40248
instance 1 40264
instance 2 40264
instance 3 40264
instance 4 40264
instance 5 40264
instance 6 40264
instance 7 40264
instance 8 40264
...
instance 99 40264
-------------------------------------------
instance 0 40264
instance 1 40280
instance 2 40280
instance 3 40280
instance 4 40280
instance 5 40280
instance 6 40280


Actual result:
--------------
Content-type: text/html
X-Powered-By: PHP/5.0.4

instance 0 40248
instance 1 40288
instance 2 40304
instance 3 40320
instance 4 40336
instance 5 40352
instance 6 40368
instance 7 40384
instance 8 40400
...
instance 99 41856
-------------------------------------------
instance 0 41856
instance 1 41872
instance 2 41872
instance 3 41872
instance 4 41872
instance 5 41872
instance 6 41872


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-13 17:01 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is caching - and expected - it will only go up until a certain point.
 [2005-04-13 20:16 UTC] jerome at kingofsofa dot org
I do confirm that it stops in the given example. I replaced the for into a while(1) and could see that a limit could be reached.

Though in my current script which is way more complex, it looks like this limit can exceed the memory_limit and thus cause the script to die.

I will play with memory_limit and see if my script does not end up eating the whole memory.

Any way to set/tune the caching system ? (maybe even turn it off)
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Apr 05 11:01:23 2020 UTC