Question: **Test One:**

```
class Entity { }

$entities = array();
echo "START: ". number_format(memory_get_usage()) . "\n";
for($i = 0; $i < 100000; ++$i)
{
    $entities[] = new Entity();
}
echo "BEFORE UNSET: ". number_format(memory_get_usage()) . "\n";
unset($entities);
echo "AFTER UNSET: ". number_format(memory_get_usage()) . "\n";

```

Output:

```
START: 631,664
BEFORE UNSET:44,404,904
AFTER UNSET: 8,954,568

```

---

**Test Two:**

```
class Entity { }

$entities = array();
echo "START: ". number_format(memory_get_usage()) . "\n";
for($i = 0; $i < 100000; ++$i)
{
    $entity = new Entity();
    $entities[] = &$entity;
}
echo "BEFORE UNSET: ". number_format(memory_get_usage()) . "\n";
unset($entities);
echo "AFTER UNSET: ". number_format(memory_get_usage()) . "\n";

```

Output:

```
START: 631,664
BEFORE UNSET: 10,480,480
AFTER UNSET: 631,752

```

After i had trouble with memory limit, I played around with it a bit...

So after that i wonder how does garbage collection really work:

1. Why does test **one** need more memory than test **two**?
2. Why does php keep memory after unsetting the array in test **one**?

thx dave

Answer: 
select id, value from foo is going to return the whole table. The 2-3 seconds you mention could include the time it takes to transfer your results. This can often be much longer than it takes you database server to execute the actual query.
Add an index to the fields used in the where clause.