[DC-904] Doctrine_Query (execute / fetchOne) memory leak Created: 29/Oct/10  Updated: 03/Dec/10

Status: Open
Project: Doctrine 1
Component/s: None
Affects Version/s: 1.2.3
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Marcin Dryka Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 3
Labels: None
Environment:

$ ./symfony -V
symfony version 1.4.8 (/home/marcin.dryka/htdocs/leak/lib/vendor/symfony/lib)

$ php -v
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:41:55)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Ubuntu Server (lucid)



 Description   

I've created new symfony 1.4.8 project:

$ ./symfony -V
symfony version 1.4.8 (/home/marcin.dryka/htdocs/leak/lib/vendor/symfony/lib)

$ php -v
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:41:55)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

and set the database schema as follows:

$ cat config/doctrine/schema.yml
Example:
columns:
col1: string(255)
col2: string(255)
col3: string(255)
col4: string(255)
col5: string(255)
col6: string(255)

I created a task that contains a Doctrine_query call

(...)
protected function execute($arguments = array(), $options = array())
{
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();

while(1)
{
$m = xdebug_memory_usage();
$q = Doctrine_Query::create()
->from('Example');
$o = $q->fetchOne();

if (false !== $o))

{ $o->free(true); }

unset($q, $o);

printf("Delta: %s Value: %s\n",
xdebug_memory_usage()-$m,
xdebug_memory_usage()
);
}
}
(...)

Unfortunately, memory usage is increasing:
./symfony leak
Delta: 3285264 Value: 10651596
Delta: 12944 Value: 10664448
Delta: 12952 Value: 10677308
Delta: 12932 Value: 10690148
Delta: 12932 Value: 10702988
Delta: 12932 Value: 10715828
Delta: 12932 Value: 10728668
Delta: 12932 Value: 10741508
Delta: 12932 Value: 10754348
Delta: 12932 Value: 10767188

Tested with and without data in database - result is the same.



 Comments   
Comment by sonic wang [ 03/Dec/10 ]

i found this bug too.

$rcs = $query->execute(array(),\Doctrine_Core::HYDRATE_ON_DEMAND);
$query->free();
//write to new table
foreach ($rcs as $rc)

{ $new = $table->create($rc->toArray()); $new->save(); $new->free(true); //free memory $rc->free(true); }

hydrate not cause memory leak

bug hydrate record will cause leak

so iterate Doctrine_collection will cause memory leak

Comment by Marcin Dryka [ 03/Dec/10 ]

Changing hydration doesn't work for me. Same result for:
HYDRATE_ON_DEMAND
HYDRATE_RECORD
HYDRATE_ARRAY

Generated at Thu Aug 28 13:19:57 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.