<p>I have a habit of keeping my variable usage to a bare minimum.  So I'm wondering if there is any advantage to be gained by the following:</p>

<pre><code>$query = $mysqli-&gt;query('SELECT * FROM `people` ORDER BY `name` ASC LIMIT 0,30');

// Example 1
$query = $query-&gt;fetch_assoc();

// Example 2
$query_r = $query-&gt;fetch_assoc();
$query-&gt;free();
</code></pre>

<p>Now if I'm right Example 1 should be more efficient as <code>$query</code> is <code>unset</code> when I reassign it  which should free any memory associated with it. However there is a method (<code>MySQLi_Result::free()</code>) which frees associated memory - is this the same thing?</p>

<p>If I don't call <code>::free()</code> to free any memory associated with the result but <code>unset</code> it by reassigning the variable am I doing the same thing? I don't know how to log this sort of thing - does anyone have some ideas?</p>

The
manual
seems to suggest that you should still be using
```
free()
```
to release the memory. I believe the reasoning is that
```
free()
```
is freeing the memory in
MySQL
, not in PHP. Since PHP can't garbage-collect for MySQL, you need to call
```
free()
```
.