|  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.
Block user comment
Status: Assign to:
Bug Type:
From: grzegorz129 at gmail dot com
New email:
PHP Version: OS:


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

Test script:
echo memory_get_usage(true)/1024 . "\n";

    function callFunc($i = 0) {
        if ($i < 100000) {

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

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-05 19:26 UTC]
-Status: Open +Status: Not a bug
 [2016-12-05 19:26 UTC]
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: Thu Aug 13 03:01:29 2020 UTC