php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30053 php leaks memory when using references
Submitted: 2004-09-10 18:20 UTC Modified: 2004-09-15 17:02 UTC
Votes:41
Avg. Score:4.5 ± 1.2
Reproduced:25 of 28 (89.3%)
Same Version:10 (40.0%)
Same OS:17 (68.0%)
From: hkmaly at bigfoot dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.3.8 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-09-10 18:20 UTC] hkmaly at bigfoot dot com
Description:
------------
If I play with references, I found php doesn't properly free
all memory in arrays with references ... for example don't free all memory in local variables of function. By repeating calling that function, leak can lead to consumation of all allowed memory.

BTW, submited also as http://bugs.gentoo.org/show_bug.cgi?id=63559


Reproduce code:
---------------
<?php

function testLeak()
{
    $a=array("jablka","hrusky","petr"=>"zeli");
    foreach($a as $k=>$v) {
        $b[$k]=&$a;
        $b[$k]['names']=&$a;
    }
    return($b);
}

echo memory_get_usage()."\n";
for($i=0;$i<200000;$i++) {
  testLeak();
  echo memory_get_usage()."\n";
}

 ?>


Expected result:
----------------
Something as 
20720
21816
22144
22144
22144
....
22144
22144
22144




Actual result:
--------------
20720
21816
22144
.....
.....
.....
16775400
16775728
16776056
16776384

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate
32 bytes) in /castle/hkmaly/programy/php/test_leak.php on line 6




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-15 10:52 UTC] sniper@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

circular references, blaa blaa, search the bug db for couple of hundred other similar bug reports. (Won't fix)

 [2004-09-15 17:02 UTC] hkmaly at bigfoot dot com
Couple of hundred ? I don't found ANYTHING with http://bugs.php.net/search.php?search_for=circular+references&boolean=1&limit=10&order_by=&direction=ASC&cmd=display&status=All&php_os=&phpver=&assign=&author_email=&bug_age=
and only one which look similar with http://bugs.php.net/search.php?search_for=circular+references&boolean=0&limit=10&order_by=&direction=ASC&cmd=display&status=All&bug_type%5B%5D=Scripting+Engine+problem&php_os=&phpver=&assign=&author_email=&bug_age=0 ... maybee your bug-finding system needs some work.

That similar one is http://bugs.php.net/bug.php?id=5620 with answer "leaking memory is the intended behaviour using circular references" and "PHP does not do circular references." ... and that leak even has NOT circular references - only multiple references to same array.
(On the other hand, original code, before I tried to found minimal case, HAS circular references).

Also, there are no "circular references" in PHP manual and "reference counting" is only in user contributed note starting "I had trouble digging this out, ...".
I didn't know I must read manual for zend ...

Can you tell me more ? Like some other, more simmilar bug number, if it's better in PHP 5, will be in PHP 6 or if I just must learn perl (or lisp) ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC