php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73659 Recursive call leaks memory
Submitted: 2016-12-05 18:47 UTC Modified: 2016-12-05 19:26 UTC
From: grzegorz129 at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 7.1.0 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grzegorz129 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-05 18:47 UTC] grzegorz129 at gmail dot com
Description:
------------
I've found very strange behavior, which is (unfortunately) consistent across multiple PHP versions: https://3v4l.org/ppe5R

Test script:
---------------
<?php
gc_enable();
echo memory_get_usage(true)/1024 . "\n";

    function callFunc($i = 0) {
        if ($i < 100000) {
           gc_collect_cycles();
           callFunc(++$i);
        }
    }

callFunc();
gc_collect_cycles();
echo memory_get_usage(true)/1024 . "\n";

callFunc();
gc_collect_cycles();
echo memory_get_usage(true)/1024 . "\n";

Expected result:
----------------
Memory should be freed after recursion.

Actual result:
--------------
Memory is retained during lifetime of a recursion, but it's never freed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-05 19:26 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2016-12-05 19:26 UTC] nikic@php.net
memory_get_usage(true) reports memory as allocated by the memory manager. This occurs in 2MB chunks, and these chunks may be cached. What you're seeing here is that the memory manager ends up retaining two chunks.

To check for leaks, use memory_get_usage() without "true".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Feb 22 23:01:25 2020 UTC