title: Laravel Response::json() exhausts memory
body: <p>I have an application which sometimes returns chunks of HTML; in this case I have to return a large table and the memory gets exhausted.</p>
  
  <p>I have a macro set up, which checks that the data to return is not larger than the allowed json limit;</p>
  
  <pre><code>Response::macro('jsonWithValidation', function($response) {
      if(strlen(serialize($response)) &gt; 125000000)
          $response = array(
              'status' =&gt; 200,
              'execute_also' =&gt; array(
                  'notify("warning", "Data too large to be sent over json");'
              )
          );
  
      return Response::json($response, $response['status']);
  });
  </code></pre>
  
  <p>This script works as a charm; the problem I'm facing now is that <strong>the last <code>Response::json</code> exhausts memory</strong>. This means that my response is not too large to be sent over json, but the Laravel method (I'm running Laravel 4.2) crashes everything.</p>
  
  <p>Ideally, at this point of the code I could have two options:</p>
  
  <ul>
  <li>send everything with basic php, but I believe the Laravel function is pretty basic already</li>
  <li>clear the memory I won't need for the response</li>
  </ul>
  
  <p>Ideally I would like to use the second option, but I have no idea if this could be done... so <strong>what should I do to avoid exceeding memory limit?</strong></p>
  
  <p>EDIT:
  This is the error I get</p>
  
  <pre><code>[05-May-2016 14:19:42 Europe/Rome] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 64 bytes) in C:\wamp\www\project_ski\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 446
  </code></pre>