memory - Why is PHP Doctine's free() not working? -
this 1 of doctrine users out there. have php cli daemon process checks table every n seconds find entries haven't been processed. it's fifo. anyways, exceed memory allocated php becuase doctrine not free it's resources. combat problem provides free query object. can't seem make work though. here's code:
22 print "you using " . (memory_get_usage() / 1024). "\n"; 23 $query = doctrine_query::create() 24 ->from('submissionqueue s') 25 ->where('s.time_acted_on null') 26 ->orderby('s.time_queued') 27 ->limit(1) 28 ->execute(); 29 print $query[0]->time_queued . "\n"; 30 $query->free();
any ideas doing wrong?
edit: using 1.0.3
edit: have tried of below suggestions. hopeful unset()
had in there before found free()
.
here more of code possibly aid in help. before question opening , closing of connection daemon process spawns children , have experienced connection has unique.
1 <?php 2 3 require_once('/usr/local/lib/php/doctrine/lib/doctrine.php'); 4 5 spl_autoload_register(array('doctrine', 'autoload')); 6 7 $manager = doctrine_manager::getinstance(); 8 $manager->setattribute('model_loading','conservative'); 9 doctrine::loadmodels('lib/model/master'); 10 11 while(1){ 12 print "you using " . intval(memory_get_usage() / 1024) . "\n"; 13 $manager->connection('********************************************','master'); 14 $query = doctrine_query::create() 15 ->from('submissionqueue s') 16 ->where('s.time_acted_on null') 17 ->orderby('s.time_queued') 18 ->limit(1) 19 ->execute(); 20 print "[" . $query[0]->time_queued . "]\n"; 21 $query->free(); 22 unset($query); 23 $query = null; 24 $manager->closeconnection(doctrine_manager::getinstance()->getconnection('master')); 25 sleep(5); 26 } 27
some sample output:
you using 14949kb [2008-11-17 13:59:00] using 14978kb [2008-11-17 13:59:00] using 15007kb [2008-11-17 13:59:00] using 15035kb [2008-11-17 13:59:00] using 15064kb [2008-11-17 13:59:00] using 15093kb [2008-11-17 13:59:00] using 15121kb [2008-11-17 13:59:00] using 15150kb [2008-11-17 13:59:00] using 15179kb [2008-11-17 13:59:00] using 15207kb [2008-11-17 13:59:00] using 15236kb [2008-11-17 13:59:00] using 15265kb [2008-11-17 13:59:00] using 15293kb [2008-11-17 13:59:00] using 15322kb
the problem is, free()
not remove doctrine objects memory eliminates circular references on objects, making possible garbage collector cleanup objects. please see 23.6 free objects in doctrine manual:
as of version 5.2.5, php not able garbage collect object graphs have circular references, e.g. parent has reference child has reference parent. since many doctrine model objects have such relations, php not free memory when objects go out of scope.
for php applications, problem of little consequence, since php scripts tend short-lived. longer-lived scripts, e.g. bulk data importers , exporters, can run out of memory unless manually break circular reference chains. doctrine provides free() function on doctrine_record, doctrine_collection, , doctrine_query eliminates circular references on objects, freeing them garbage collection.
the solution should unset()
$query
object after using free()
:
$query = doctrine_query::create() ->from('submissionqueue s') ->where('s.time_acted_on null') ->orderby('s.time_queued') ->limit(1); $query->execute(); print $query[0]->time_queued . "\n"; $query->free(); unset($query); // perhaps $query = null; work
Comments
Post a Comment