Edit report at https://bugs.php.net/bug.php?id=62111&edit=1
ID: 62111 Comment by: juzna dot cz at gmail dot com Reported by: hosiplan at gmail dot com 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.4RC1 Block user comment: N Private report: N New Comment: Leaks with mysql, no leaks with sqlite. No need to fetchAll(); execute() is enough to get leaks Previous Comments: ------------------------------------------------------------------------ [2012-05-22 20:12:17] hosiplan at gmail dot com affected version ------------------------------------------------------------------------ [2012-05-22 20:10:33] hosiplan at gmail dot com 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"; } ------------------------------------------------------------------------ [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