Free result memory
(PHP 4, PHP 5, PECL mysql:1.0)
Example 1441. A mysql_free_result() example
Code Examples / Notes » mysql_free_result
You not need to use this if you are using PHP 4.
The comment below this comment may explain why it's actually costing more memory.
yes, i encountered that too. as far as i could tell, that's because the script is stored in memory after being compiled and that's as much more memory as it needs for a call to that function.
if you always get lotsa data in your results, using this function will decrease memory usage tho, unless you use non-buffered queries (which are preferable unless you absolutely *have* to use mysql_seek(), or you need to do another query while the last one hasn't finished reporting back, as they can provide a small speedup)
Using this function may actually increase the amount of memory used. In my case, the script used 208 bytes less memory when *not* using mysql_free_result().
Check for yourself: call memory_get_usage() at the end of the script.
If you're seeing warnings like "Warning: Unknown: 6 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0" and want to turn them off, set mysql.trace_mode = Off in your php.ini
ALWAYS use this function! I just encountered a bug in my code where I forgot to use this function. I also happen to be using mysql_pconnect() for a persistent connection. If you forget to free the result, it can hold the old result set open indefinitely within the HTTP process.
The upshot (in my application) was that I did updates that happened in a different HTTP process, but they mysteriously didn't show up in another HTTP process. After panicking that MySQL had mysterious data corruption and/or synchronization problems, I traced it back to this where an old result set was held open.