<p>I am getting the error in the image below.  It is not always generated by the same file (in this case ".../IOHelper.php").</p>

<p><a href="https://i.sstatic.net/BSKZP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BSKZP.png" alt="enter image description here"></a></p>

<p>I can't quite figure out what is causing this, Can anyone provide some insight into what can cause this error specifically (I understand there is a memory issue) and maybe point to where I could be looking as far as a culprit.  </p>

<p>My hunch is it could be due to this relational query being done on users (team is what it is called here).</p>

<pre><code>{% set relatedDepartment = craft.entries.section('departments').relatedTo({
     sourceElement: teamEntry,
     field: 'departmentLabel'
}) %}
</code></pre>

<p>My understanding is this is set up correctly and should only pull the department information related to that entry in the loop?</p>

<p>the whole block looks like this</p>

<pre><code>{% for teamEntry in craft.entries.section('team').order('title').find() %}

    {% set relatedDepartment = craft.entries.section('departments').relatedTo({
        sourceElement: teamEntry,
        field: 'departmentLabel'
    }) %}

      &lt;div class="photo team-photo col-xs-6 col-sm-4 col-md-3 col-lg-2 team-photo-{% for department in teamEntry.departmentLabel %}{{ department.id }}{% endfor %} all" data-department-id="{% for department in teamEntry.departmentLabel %}{{ department.id }}{% endfor %}" data-border-color="{% for department in relatedDepartment %}{{ department.departmentColor }}{%endfor%}"&gt;

        {% set mad = teamEntry.imgMad.first() %}
        {% set disgusted = teamEntry.imgDisgusted.first() %}
        {% set sad = teamEntry.imgSad.first() %}
        {% set neutral = teamEntry.imgNeutral.first() %}
        {% set content = teamEntry.imgContent.first() %}
        {% set happy = teamEntry.imgHappy.first() %}

        {% if neutral | length&gt;0 %}
          &lt;img src="{{ neutral.url }}" class="image mood team-{% for department in teamEntry.departmentLabel %}{{ department.id }}{% endfor %}"/&gt;
        {% else %}
          &lt;img src="/img/nophoto.png" class="team-{% for department in teamEntry.departmentLabel %}{{ department.id }}{% endfor %} image" alt="no photo for {{ teamEntry.title }}"/&gt;
        {% endif %}

        &lt;div class="names"&gt;{{ teamEntry.title }}&lt;br&gt;&lt;span&gt;{% for department in teamEntry.departmentLabel %}{{ department.title }}{% endfor %}&lt;/span&gt;&lt;/div&gt;

        &lt;div class="hovertext t3modal" href="#modalContent" data-slug-url="/people/detail?q={{ teamEntry.slug }}" data-slug="{{ teamEntry.slug }}" &gt;
          &lt;div class="inhover"&gt;
            &lt;span class="title"&gt;View Profile&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
 {% endfor %}
</code></pre>

CC BY-SA 3.0
2016-08-12T19:48:47.477Z
Voting to close this. If you're running out of memory, the only real solution is to increase the allocation to PHP. See also:  [Fatal error: Allowed memory size of 134mb exhausted](http://craftcms.stackexchange.com/questions/2674/fatal-error-allowed-memory-size-of-134mb-exhausted)
RitterKnight
CC BY-SA 3.0
2016-08-16T16:45:04.427Z
The question as asked is a duplicate, and will be closed as such. However, the _real_ question should be "why is this code so inefficient?". I highly recommend looking into [eager loading](https://craftcms.com/docs/templating/eager-loading-elements) to vastly improve your load time here.
Lindsey D
<craft-pro>
How to solve "fatal error: out of memory"
# How to solve "fatal error: out of memory"

(Asked by: username_0 on 2016-08-12)

I am getting the error in the image below.  It is not always generated by the same file (in this case ".../IOHelper.php").

I can't quite figure out what is causing this, Can anyone provide some insight into what can cause this error specifically (I understand there is a memory issue) and maybe point to where I could be looking as far as a culprit.  
My hunch is it could be due to this relational query being done on users (team is what it is called here).
{% set relatedDepartment = craft.entries.section('departments').relatedTo({
     sourceElement: teamEntry,
     field: 'departmentLabel'
}) %}

My understanding is this is set up correctly and should only pull the department information related to that entry in the loop?
the whole block looks like this
{% for teamEntry in craft.entries.section('team').order('title').find() %}

    {% set relatedDepartment = craft.entries.section('departments').relatedTo({
        sourceElement: teamEntry,
        field: 'departmentLabel'
    }) %}

      

        {% set mad = teamEntry.imgMad.first() %}
        {% set disgusted = teamEntry.imgDisgusted.first() %}
        {% set sad = teamEntry.imgSad.first() %}
        {% set neutral = teamEntry.imgNeutral.first() %}
        {% set content = teamEntry.imgContent.first() %}
        {% set happy = teamEntry.imgHappy.first() %}

        {% if neutral | length>0 %}
          
        {% else %}
          
        {% endif %}

        {{ teamEntry.title }}{% for department in teamEntry.departmentLabel %}{{ department.title }}{% endfor %}

        
          
            View Profile
          
        
      
 {% endfor %}

**Tags:** craft-pro

> **Comments:**
> **username_1**: Voting to close this. If you're running out of memory, the only real solution is to increase the allocation to PHP. See also:  [Fatal error: Allowed memory size of 134mb exhausted](http://craftcms.stackexchange.com/questions/2674/fatal-error-allowed-memory-size-of-134mb-exhausted)  
> **username_2**: The question as asked is a duplicate, and will be closed as such. However, the _real_ question should be "why is this code so inefficient?". I highly recommend looking into [eager loading](https://craftcms.com/docs/templating/eager-loading-elements) to vastly improve your load time here.  

---

## 0 answers

