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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC