Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Debug] Memory leak in Debug\ErrorHandler #25965

Copy link
Copy link
Closed
@nanasess

Description

@nanasess
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4.4

Memory leak has occurred with a PR of #25829, reproduced with the following code.

composer create-project symfony/skeleton memory-leak-check "^3.4"
cd memory-leak-check
composer req phpunit log browser-kit psr/log
<?php

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MemoryLeakCheckTest extends WebTestCase
{
    protected function setUp()
    {
        parent::setUp();
        for ($i = 0; $i < 1000; $i++) {
            self::createClient()->request('GET', '/');
        }
    }

    protected function tearDown()
    {
        var_dump((memory_get_usage() / 1024 / 1024));
    }
    function testEEE1()  { 
    }
    function testEEE2()  { 
    }
    function testEEE3()  { 
    }
    function testEEE4()  { 
    }
    function testEEE5()  { 
    }
    function testEEE6()  { 
    }
    function testEEE7()  { 
    }
    function testEEE8()  { 
    }
    function testEEE9()  { 
    }
    function testEEE10()  { 
    }
    function testEEE11()  { 
    }
    function testEEE12()  { 
    }
    function testEEE13()  { 
    }
    function testEEE14()  { 
    }
    function testEEE15()  { 
    }
    function testEEE16()  { 
    }
}

We got this result.

memory-leak-check% php vendor/bin/simple-phpunit
PHPUnit 6.3.1 by Sebastian Bergmann and contributors.

Testing Project Test Suite
Rfloat(51.022598266602)
Rfloat(96.973236083984)
Rfloat(143.40355682373)
Rfloat(188.87760162354)
Rfloat(236.3078994751)
Rfloat(281.73819732666)
Rfloat(327.21188354492)
Rfloat(372.64218139648)
Rfloat(422.07247924805)
Rfloat(467.50344085693)
Rfloat(512.9732208252)
Rfloat(558.40351867676)
Rfloat(603.83381652832)
Rfloat(649.30750274658)
Rfloat(694.73780059814)
R                                                  16 / 16 (100%)float(740.16809844971)


Time: 35.43 seconds, Memory: 748.00MB

It is possible to fix it with the following patch.

index 047883a70c..0b7e4269bb 100644
--- a/src/Symfony/Component/Debug/ErrorHandler.php
+++ b/src/Symfony/Component/Debug/ErrorHandler.php
@@ -134,7 +134,7 @@ class ErrorHandler
         if (!$replace && $prev) {
             restore_error_handler();
         }
-        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] === $handler) {
+        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && get_class($prev[0]) === get_class($handler)) {
             restore_exception_handler();
         } else {
             $handler->setExceptionHandler($prev);

The results of the modified

php vendor/bin/simple-phpunit
PHPUnit 6.3.1 by Sebastian Bergmann and contributors.

Testing Project Test Suite
Rfloat(5.1568069458008)
Rfloat(5.1869430541992)
Rfloat(5.1967391967773)
Rfloat(5.2065353393555)
Rfloat(5.2163314819336)
Rfloat(5.2261276245117)
Rfloat(5.2359237670898)
Rfloat(5.245719909668)
Rfloat(5.2555160522461)
Rfloat(5.2656173706055)
Rfloat(5.2754135131836)
Rfloat(5.2852096557617)
Rfloat(5.2950057983398)
Rfloat(5.304801940918)
Rfloat(5.3145980834961)
R                                                  16 / 16 (100%)float(5.3243942260742)


Time: 35.72 seconds, Memory: 6.00MB

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.