As I understand, as the reference count of an object becomes 0, PHP's garbage collector takes care of destruction of objects.
I have a utility function for database connections, where I create a PDO object and return the object to the calling script for PDO operations.
Since I have this code all over the place of the webserver scripts, which is going to serve mobile client requests, it is critical I don't overlook a detail and have memory leaks when the app goes live.
Do you see any problems here?
in connectDB.php:
function mySQLConnect() {
.....
.....
try
{
$dbh = new PDO($dsn, $user, $password, $options); // Ref Count=1
....
return $dbh;
}
catch (PDOException $e)
{
....
return NULL;
}
}
in a PHP script:
include 'connectDB.php';
try
{
$dbh = mySQLConnect(); // Ref Count =2
....
....
} //Script Stops, Ref Count becomes 0 and memory is freed- or is it?
catch (Exception $e)
{
....
....
}
Thanks in advance!