Answers.Body: <p>Increase the amount of memory available to PHP through <a href="https://secure.php.net/manual/en/ini.core.php#ini.memory-limit" rel="nofollow">memory_limit</a> is one option.</p>
  
  <p>Another option is to reduce the amount of data (and therefore memory) you're dealing with in one request.</p>
  
  <p>You don't share what <code>craft.locationAPI.fetchAllLocations()</code> is actually doing, but if you're returning results as Craft models, there is a significant overhead (performance and memory-wise) doing that with large data sets in Craft 2.x.  You could look and return more primitive data structures.</p>
  
  <p>Another alternative is to batch the results and retrieve them over multiple AJAX queries.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-03T02:56:21.157Z
Answers.Text: Thanks for the heads up, Brad. I think for this particular use case I'll not worry about caching because the amount of memory exhausted and queries used is fairly small. 21,304Kb / 18. I might use these options in other cases, however!
Answers.UserDisplayName: Aaron Bushnell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-03T02:25:30.630Z
Answers.LastActivityDate: 2016-03-03T02:25:30.630Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm getting a fatal error when wrapping a loop with <code>{% cache %}{% endcache %}</code> tags. The full error is:</p>
  
  <blockquote>
    <p>Fatal error: Allowed memory size of 134217728 bytes exhausted (tried
    to allocate 32 bytes) in /craft/app/helpers/StringHelper.php on line
    473</p>
  </blockquote>
  
  <p>Here's a small code sample of what I'm doing</p>
  
  <pre><code>{!--
    `craft.locationAPI.fetchAllLocations` grabs ~200 entries with related data via custom SQL queries.
    Doing this because craft.entries was throwing memory limit errors.
  --}
  
  {% cache %}
    {% for entry in craft.locationAPI.fetchAllLocations() %}
      ...
    {% endfor %}
  {% endcache %}
  </code></pre>
  
  <p>I'm guessing this is because the amount of data getting returned (~13300 lines in "View Source") is too large for the <code>encodeMb4</code> function in StringHelper.php.</p>
  
  <p>Anything I can do to avoid this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-03T01:31:38.037Z
Comments.Text: Pardon me asking the obvious here, but can you increase your php.ini file's memory_limit from 128M to 256M?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-03T01:56:08.143Z
Comments.Text: That did the trick! I think that'll be fine for the development server, but I don't think we'll be able to set the production server quite this high. Prolly outta luck on this one?
Comments.UserDisplayName: Aaron Bushnell
Tags: <entries><cache>
Title: Fatal error in StringHelper.php when using cache block around loop
ThreadText: # Fatal error in StringHelper.php when using cache block around loop
  
  (Asked by: username_0 on 2016-03-03)
  
  I'm getting a fatal error when wrapping a loop with `{% cache %}{% endcache %}` tags. The full error is:
  
  > Fatal error: Allowed memory size of 134217728 bytes exhausted (tried
  > to allocate 32 bytes) in /craft/app/helpers/StringHelper.php on line
  > 473
  
  Here's a small code sample of what I'm doing
  
  ```
  {!--
    `craft.locationAPI.fetchAllLocations` grabs ~200 entries with related data via custom SQL queries.
    Doing this because craft.entries was throwing memory limit errors.
  --}
  
  {% cache %}
    {% for entry in craft.locationAPI.fetchAllLocations() %}
      ...
    {% endfor %}
  {% endcache %}
  
  ```
  
  I'm guessing this is because the amount of data getting returned (~13300 lines in "View Source") is too large for the `encodeMb4` function in StringHelper.php.
  
  Anything I can do to avoid this?
  
  **Tags:** entries, cache
  
  > **Comments:**
  > **username_1**: Pardon me asking the obvious here, but can you increase your php.ini file's memory_limit from 128M to 256M?  
  > **username_0**: That did the trick! I think that'll be fine for the development server, but I don't think we'll be able to set the production server quite this high. Prolly outta luck on this one?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-03. Score: 1 | Accepted answer
  
  Increase the amount of memory available to PHP through [memory\_limit](https://secure.php.net/manual/en/ini.core.php#ini.memory-limit) is one option.
  
  Another option is to reduce the amount of data (and therefore memory) you're dealing with in one request.
  
  You don't share what `craft.locationAPI.fetchAllLocations()` is actually doing, but if you're returning results as Craft models, there is a significant overhead (performance and memory-wise) doing that with large data sets in Craft 2.x. You could look and return more primitive data structures.
  
  Another alternative is to batch the results and retrieve them over multiple AJAX queries.
  
  > **Comments:**
  > **username_0**: Thanks for the heads up, username_1. I think for this particular use case I'll not worry about caching because the amount of memory exhausted and queries used is fairly small. 21,304Kb / 18. I might use these options in other cases, however!  
  
  ---
  
  