Issue 1:
Q
A

Bug report?
yes

Feature request?
no

BC Break report?
no

RFC?
no

Symfony version
3.4.4

Hello guys,

after updating from 3.4.3 to 3.4.4 we noticed a 10x increase in memory usage when running our testsuite. To analyze the issue, we profiled both execution (3.4.3 and 3.4.4) with blackfire (see links below). Looking at the comparison of both runs we had the idea to revert #25835. Running blackfire again shows a decreased memory consumption.

The cache was cleared prior to each run.

If you need further information let me know. Unfortunately I can not share the code base.

3.4.4: https://blackfire.io/profiles/22ed34e8-9827-48ef-8ed4-7eaf9a6218c5/graph

3.4.3: https://blackfire.io/profiles/eacbfc2d-6592-4003-9d16-6c967286d36e/graph

3.4.4 with reverted #25835: https://blackfire.io/profiles/df3e9f4a-d28c-4a4e-8cf9-ea48a1659328/graph

Comparisons:

3.4.3 -> 3.4.4

3.4.4 -> 3.4.4 w/o 25835

Issue 2:
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