Edit report at https://bugs.php.net/bug.php?id=62111&edit=1
ID: 62111 Updated by: u...@php.net 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: There is no leak with MySQL. Memory usage increases, that's it. ==6216== LEAK SUMMARY: ==6216== definitely lost: 0 bytes in 0 blocks ==6216== indirectly lost: 0 bytes in 0 blocks ==6216== possibly lost: 0 bytes in 0 blocks ==6216== still reachable: 54 bytes in 2 blocks ==6216== suppressed: 0 bytes in 0 blocks ==6216== Rerun with --leak-check=full to see details of leaked memory Previous Comments: ------------------------------------------------------------------------ [2012-06-11 13:48:11] juzna dot cz at gmail dot com The same causes PHP to crash completely on Windows 32bit with MSSQL server (using sqlsrv driver). I guess the root cause will be related. ------------------------------------------------------------------------ [2012-05-22 20:39:55] juzna dot cz at gmail dot com Leaks with mysql, no leaks with sqlite. No need to fetchAll(); execute() is enough to get leaks ------------------------------------------------------------------------ [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