I’ve been looking online and every article I’ve come across seems to say something slightly different. If I’m working with a resultset and the program exits before releasing the results what exactly happens?
Is there a better way to ensure that it always happens? The same goes for database connections.
if($statement->fetch()) {
exit("Result!");
}
$statement->free_result();
The
free_resulttells the database engine it can release the result set.It only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script’s execution.
You can use
register_shutdown_functionto make sure your results are freed from memory