mysqli_free_result necessary?

JoJo picture JoJo · Dec 30, 2012 · Viewed 16.1k times · Source

I was looking through my code and read that it was recommened to use mysqli_free_result when your result object is not needed anymore. But after seeing that each query is outputed to the $result variable repeatedly throughout the script, I am wondering if mysqli_free_result would really be necessary. Seems like each time a query is ran the $result variable is already being wiped clean and set to a new result. Just curious if anyone has any input on this.

Answer

Michael Mior picture Michael Mior · Dec 30, 2012

It’s never strictly necessary, but it's good practice to keep an eye on resources you’re using and know when you don't need them anymore.

It’s pretty minimal effort to drop in that extra line of code, so I would just do it every time you're finished with a result set. It has the added bonus of making it clear to someone reading your code when you’ve finished with a resource.