Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP80 / Possible memory leak on array_filter vs opcache #60

Closed
quazardous opened this issue Jul 4, 2021 · 2 comments
Closed

PHP80 / Possible memory leak on array_filter vs opcache #60

quazardous opened this issue Jul 4, 2021 · 2 comments
Labels

Comments

@quazardous
Copy link

I've experienced a memory leak using array_filter when both opcahe and xhprof are enabled.

here is a demo script:

<?php
// array_filter_short.php
namespace Somewhere\On\Earth;
class Foo {
    function leaking(array $array) {
        $f = function ($array) {
            return \array_filter($array, fn($item) => !is_null($item));
        };
        for (;;) {
            $clone = (array) $array;
            $res = $f($clone);
            printf("memory: %d\n", \memory_get_usage());
            unset($clone, $res);
        }
    }
    function run() {
        $array = array_combine(range(1, 1000, 2), array_fill(1, 500, null));
        $array += array_combine(range(2, 1000, 2), array_fill(1, 500, true));
        $this->leaking($array);
    }
}
(new Foo())->run();

Test it with

php80 -n -dzend_extension=opcache -dopcache.enable=1 -dopcache.enable_cli=1 -dextension=xhprof.so array_filter_short.php

Here is the PHP bug I've filled
https://bugs.php.net/bug.php?id=81215

Here is the issue in phacility
phacility#105

@longxinH longxinH added the bug label Jul 4, 2021
longxinH added a commit that referenced this issue Jul 4, 2021
fix issue60 #60
@longxinH
Copy link
Owner

longxinH commented Jul 4, 2021

@quazardous Fix

@longxinH
Copy link
Owner

longxinH commented Jul 5, 2021

@longxinH longxinH closed this as completed Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants