<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.4.4</td>
</tr>
</tbody>
</table>

<p dir="auto">Hello guys,</p>
<p dir="auto">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 <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="289633837" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/25835" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/25835/hovercard" href="https://github.com/symfony/symfony/pull/25835">#25835</a>. Running blackfire again shows a decreased memory consumption.</p>
<p dir="auto">The cache was cleared prior to each run.</p>
<p dir="auto">If you need further information let me know. Unfortunately I can not share the code base.</p>
<p dir="auto">3.4.4: <a href="https://blackfire.io/profiles/22ed34e8-9827-48ef-8ed4-7eaf9a6218c5/graph" rel="nofollow">https://blackfire.io/profiles/22ed34e8-9827-48ef-8ed4-7eaf9a6218c5/graph</a><br>
3.4.3: <a href="https://blackfire.io/profiles/eacbfc2d-6592-4003-9d16-6c967286d36e/graph" rel="nofollow">https://blackfire.io/profiles/eacbfc2d-6592-4003-9d16-6c967286d36e/graph</a><br>
3.4.4 with reverted <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="289633837" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/25835" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/25835/hovercard" href="https://github.com/symfony/symfony/pull/25835">#25835</a>: <a href="https://blackfire.io/profiles/df3e9f4a-d28c-4a4e-8cf9-ea48a1659328/graph" rel="nofollow">https://blackfire.io/profiles/df3e9f4a-d28c-4a4e-8cf9-ea48a1659328/graph</a></p>
<p dir="auto">Comparisons:<br>
<a href="https://blackfire.io/profiles/compare/dbb5091e-5da7-429f-a007-de0bfcf1b29f/graph" rel="nofollow">3.4.3 -&gt; 3.4.4</a><br>
<a href="https://blackfire.io/profiles/compare/b930e7ec-b984-45da-82d4-d5bf73d20343/graph" rel="nofollow">3.4.4 -&gt; 3.4.4 w/o 25835</a></p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.4.4</td>
</tr>
</tbody>
</table>
<p dir="auto">Memory leak has occurred with a PR of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="289555668" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/25829" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/25829/hovercard" href="https://github.com/symfony/symfony/pull/25829">#25829</a>, reproduced with the following code.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="composer create-project symfony/skeleton memory-leak-check &quot;^3.4&quot;
cd memory-leak-check
composer req phpunit log browser-kit psr/log"><pre class="notranslate"><code class="notranslate">composer create-project symfony/skeleton memory-leak-check "^3.4"
cd memory-leak-check
composer req phpunit log browser-kit psr/log
</code></pre></div>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?php

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MemoryLeakCheckTest extends WebTestCase
{
    protected function setUp()
    {
        parent::setUp();
        for ($i = 0; $i &lt; 1000; $i++) {
            self::createClient()-&gt;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()  { 
    }
}"><pre class="notranslate"><span class="pl-ent">&lt;?php</span>

<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Bundle</span>\<span class="pl-v">FrameworkBundle</span>\<span class="pl-v">Test</span>\<span class="pl-v">WebTestCase</span>;

<span class="pl-k">class</span> <span class="pl-v">MemoryLeakCheckTest</span> <span class="pl-k">extends</span> <span class="pl-v">WebTestCase</span>
{
    <span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">setUp</span>()
    {
        <span class="pl-smi">parent</span>::<span class="pl-en">setUp</span>();
        for (<span class="pl-s1"><span class="pl-c1">$</span>i</span> = <span class="pl-c1">0</span>; <span class="pl-s1"><span class="pl-c1">$</span>i</span> &lt; <span class="pl-c1">1000</span>; <span class="pl-s1"><span class="pl-c1">$</span>i</span>++) {
            <span class="pl-smi">self</span>::<span class="pl-en">createClient</span>()-&gt;<span class="pl-en">request</span>(<span class="pl-s">'GET'</span>, <span class="pl-s">'/'</span>);
        }
    }

    <span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">tearDown</span>()
    {
        var_dump((memory_get_usage() / <span class="pl-c1">1024</span> / <span class="pl-c1">1024</span>));
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE1</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE2</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE3</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE4</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE5</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE6</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE7</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE8</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE9</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE10</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE11</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE12</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE13</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE14</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE15</span>()  { 
    }
    <span class="pl-k">function</span> <span class="pl-en">testEEE16</span>()  { 
    }
}</pre></div>
<p dir="auto">We got this result.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">It is possible to fix it with the following patch.</p>
<div class="highlight highlight-source-diff notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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 &amp;&amp; $prev) {
             restore_error_handler();
         }
-        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) &amp;&amp; $prev[0] === $handler) {
+        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) &amp;&amp; get_class($prev[0]) === get_class($handler)) {
             restore_exception_handler();
         } else {
             $handler-&gt;setExceptionHandler($prev);"><pre class="notranslate">index 047883a70c..0b7e4269bb 100644
<span class="pl-md">--- a/src/Symfony/Component/Debug/ErrorHandler.php</span>
<span class="pl-mi1">+++ b/src/Symfony/Component/Debug/ErrorHandler.php</span>
<span class="pl-mdr">@@ -134,7 +134,7 @@</span> class ErrorHandler
         if (!$replace &amp;&amp; $prev) {
             restore_error_handler();
         }
<span class="pl-md"><span class="pl-md">-</span>        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) &amp;&amp; $prev[0] === $handler) {</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>        if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) &amp;&amp; get_class($prev[0]) === get_class($handler)) {</span>
             restore_exception_handler();
         } else {
             $handler-&gt;setExceptionHandler($prev);</pre></div>
<p dir="auto">The results of the modified</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>