<p>Use <code>.total()</code> instead of <code>.count()</code></p>

<p><code>.count()</code> will query the db and fetch all fields for all items relating to your criteria and then count them. </p>

<p><code>.total()</code> only counts the number of items your criteria returns without all of their fields. </p>

CC BY-SA 3.0
2016-04-15T13:55:44.423Z
2016-04-15T13:55:44.423Z
Luke Pearce
<p>In addition to <a href="https://craftcms.stackexchange.com/a/14669/57">Luke's answer</a>, you might want to consider bumping your php.ini file's <a href="https://secure.php.net/manual/en/ini.core.php#ini.memory-limit" rel="nofollow noreferrer">memory_limit</a> to something higher than 128M, like 256M.</p>

CC BY-SA 3.0
2016-04-15T14:15:17.383Z
2016-04-15T14:15:17.383Z
2017-04-13T12:51:00.200Z
Brad Bell
<p>Hi I have like 2000 users in my system. I would like to get a count of the active ones, so I did it like this:</p>

<pre><code>{{craft.users.group('member').count()}}
</code></pre>

<p>but this returns the count with the limit of 100, so when I remove the limit</p>

<pre><code>{{craft.users.group('member').limit(null).count()}}
</code></pre>

<p>I got this error</p>

<pre><code>Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /Users/alex/git/website/craft/app/models/BaseModel.php on line 280
</code></pre>

<users><error><memory><count>
Count users, not enough memory error
# Count users, not enough memory error

(Asked by: username_0 on 2016-04-15)

Hi I have like 2000 users in my system. I would like to get a count of the active ones, so I did it like this:
{{craft.users.group('member').count()}}

but this returns the count with the limit of 100, so when I remove the limit
{{craft.users.group('member').limit(null).count()}}

I got this error
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /Users/alex/git/website/craft/app/models/BaseModel.php on line 280

**Tags:** users, error, memory, count


---

## 2 answers

### Answer by username_1 on 2016-04-15. Score: 3 | Accepted answer

Use `.total()` instead of `.count()`

`.count()` will query the db and fetch all fields for all items relating to your criteria and then count them.

`.total()` only counts the number of items your criteria returns without all of their fields.


---

### Answer by username_2 on 2016-04-15. Score: 0

In addition to [Luke's answer](https://craftcms.stackexchange.com/a/14669/57), you might want to consider bumping your php.ini file's [memory\_limit](https://secure.php.net/manual/en/ini.core.php#ini.memory-limit) to something higher than 128M, like 256M.


---

