[UPHPU] Freeing database resources
Lonnie Olson
lists at kittypee.com
Tue Jun 3 19:00:51 MDT 2008
On Tue, Jun 3, 2008 at 4:12 PM, Rusty Keele <rusty.keele at yahoo.com> wrote:
> However, I notice that in the same PHP manual they always free up their resources in the examples they give! Why do they do that if the resources are garbage collected? Perhaps they are just being careful coders and demonstrating best practices. Anyway, I am wondering if anybody has ever had problems by NOT freeing up MySQL resources - you know, by not calling mysql_close() or mysql_free_result().
I have always operated under the idea that freeing resources should be
handled the same way as freeing any other in memory data structure. I
don't bother deleting, undefining, freeing any variable or resource,
unless it could possibly be large and I have need to do lots of other
processing after it's use is done.
Example: A database result set. If I use the result set, and my
script completes very shortly after the result set is no longer needed
to me I just let the garbage collector/end of script clean up for me.
If I have a large array in memory, run my processing early and extract
needed data out. I then move on to do some other heavy processing,
but no longer need to access the large array, I delete the large array
as soon as I am done.
--lonnie
More information about the UPHPU
mailing list