From: Operating system: PHP version: 5.3.3 Package: PDO related Bug Type: Bug Bug description:PDO::FETCH_INTO leaks memory
Description: ------------ When assigning an object to a PDO statement via FETCH_INTO a memory leak occurs that can not be corrected through php code. A subsequent FETCH_INTO with a different object only furthers the problem. Changing the fetch mode, unsetting the statement, closing the cursor, and calling the garbage collection do not free the memory either. This bug exists in 5.2 and 5.3. Test script: --------------- <?php if (! extension_loaded('pdo_sqlite')) { dl('pdo_sqlite.so'); } $pdo = new PDO('sqlite::memory:'); echo "Start mem:".memory_get_peak_usage()."\n"; // Simple test $stmt = $pdo->prepare("select 1 as attr"); for($i=0; $i<100000; $i++) { $stmt->setFetchMode(PDO::FETCH_INTO, new StdClass); echo "mem: ".memory_get_usage()."\n"; } // End - Simple Test // Alternate test with failed remedies class test { public $attr; public function load($pdo) { $stmt = $pdo->prepare("select 1 as attr"); //$stmt->setFetchMode(PDO::FETCH_INTO, $this); // This leaks quickly $stmt->setFetchMode(PDO::FETCH_INTO, new StdClass); // This still leaks $stmt->setFetchMode(PDO::FETCH_ASSOC); // You might think this would fix the leak - no effect $stmt->closeCursor(); // No effect unset($stmt); // No effect } } for($i=0; $i<100000; $i++) { $test = new test; $test->load($pdo); if (function_exists('gc_collect_cycles')) { echo "+gc+ "; gc_collect_cycles(); // No effect } unset($test); echo "mem: ".memory_get_peak_usage()."\n"; } Expected result: ---------------- I would expect the peak memory usage to remain consisten on subsequent iterations. Actual result: -------------- The peak memory usage continues to rise until the php memory limit is hit. -- Edit bug report at http://bugs.php.net/bug.php?id=52487&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52487&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52487&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52487&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52487&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52487&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52487&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52487&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52487&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52487&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52487&r=support Expected behavior: http://bugs.php.net/fix.php?id=52487&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52487&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52487&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52487&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52487&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52487&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52487&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52487&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52487&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52487&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52487&r=mysqlcfg