From:             
Operating system: Centos 5
PHP version:      5.3.3
Package:          PDO related
Bug Type:         Bug
Bug description:Memory leak when unsetting PDOStatement and/or resultset

Description:
------------
I am noticing unexpected, inconsistent memory use when unsetting the
resultset 

of a PDOStatement and/or unsetting the statement itself.



I have attached a quick test script to illustrate the problematic behavior.
 I 

am selecting approximately 500k rows in order to make the memory usage
obvious.  

The script should be run with all of the unsets commented out and then with
some 

or all uncommented.



Run with:



no unsets: system memory usage fluctuates but relatively stable, peak
memory 

usage increases



uncommenting some or all of the unsets: system and peak usage will
continually 

increase









I understand how the memory usage could fluctuate due to garbage collection
but 

I do not understand why the addition of unsets would cause a steady
increase in 

memory usage.  This appears to be a memory leak.



Also, top/ps output for RSS/VSZ of the process matches the "peak" memory
usage 

and not the system allocated or php allocated numbers.  Is this to be
expected?

Test script:
---------------
<?php



$db = connect();



while(1){

    echo(memory_get_usage(true) . "\t" . memory_get_usage() . "\t" .
memory_get_peak_usage() . "\n");

    blah($db);

}





function blah($db){

    $sql = "select id from table LIMIT 500000";

    $stmt = $db->prepare($sql);



    $stmt->execute();

    $a = $stmt->fetchAll();

    //unset($a);



    $stmt->execute();

    $a = $stmt->fetchAll();

    //unset($a);



    //unset($stmt);

}



function connect(){

    $dsn = 'mysql:host=127.0.0.1;dbname=db;port=3306';

    $options = array(PDO::ATTR_TIMEOUT => APPLICATION_DB_PDO_TIMEOUT);

    $db = new PDO($dsn, 'user', 'pass', $options);

    return $db;

}



Expected result:
----------------
Memory usage over time should be relatively stable overall.  Peak memory
usage 

should be lowest when unsetting the first resultset.

Actual result:
--------------
Memory usage continues to increase over time if any of the unsets are
uncommented.  

Peak memory usage is halved when the first resultset is unset but it
continues to 

increase over time.

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52959&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52959&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52959&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52959&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52959&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52959&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52959&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52959&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52959&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52959&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52959&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52959&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52959&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52959&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52959&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52959&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52959&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52959&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52959&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52959&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52959&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52959&r=mysqlcfg

Reply via email to