Edit report at https://bugs.php.net/bug.php?id=62111&edit=1

 ID:                 62111
 User updated by:    hosiplan at gmail dot com
 Reported by:        hosiplan at gmail dot com
-Summary:            GC not working, when used own row class
+Summary:            MySQL PDO memory leaks, when used own result row
                     class
 Status:             Open
 Type:               Bug
 Package:            PDO related
 Operating System:   Linux
-PHP Version:        5.4.3
+PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

Sorry, I've coppied wrong code



Test script:
---------------

$db = new PDO('mysql:host=127.0.0.1;dbname=information_schema', 'root', 
'password');

class DbRow { public function __construct($stt = NULL) { } }
$begin = memory_get_usage();
for ($i=0; $i < 10 ;$i++) {
        $stt = $db->prepare("SELECT * FROM COLLATIONS");
        $stt->setFetchMode(PDO::FETCH_CLASS, 'DbRow', array($stt));
        $stt->execute();
        $rows = $stt->fetchAll();
        echo number_format((memory_get_usage() - $begin) / 1000000, 2, '.', ' 
'), " MB\n";
}


Previous Comments:
------------------------------------------------------------------------
[2012-05-22 20:05:25] hosiplan at gmail dot com

Description:
------------
When PDO is told to use my row class and pass PDOStatement into it, it creates 
cyclic reference, that prevents GC from deleting the row data, when not 
required 
anymore.

Test script:
---------------
$db = new PDO('mysql:host=127.0.0.1;dbname=information_schema', 'root', 
'password');

class DbRow { public function __construct($stt = NULL) { } }
$begin = memory_get_usage();
for ($i=0; $i < 10 ;$i++) {
        $stt = $db->prepare("SELECT * FROM COLLATIONS");
        $stt->setFetchMode(PDO::FETCH_CLASS, 'DbRow');
        $stt->execute();
        $rows = $stt->fetchAll();

        echo number_format((memory_get_usage() - $begin) / 1000000, 2, '.', ' 
'), " MB\n";
}

Expected result:
----------------
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB
0.05 MB

Actual result:
--------------
0.00 MB
0.05 MB
0.10 MB
0.14 MB
0.19 MB
0.24 MB
0.29 MB
0.34 MB
0.38 MB
0.43 MB


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62111&edit=1

Reply via email to