symfony repository memory leak -
this code in trollservice.php (symfony 2.3):
public function trolling() { $repository = $this->entitymanager->getrepository('trollbundle:troll'); $trolls = $repository->findall(); //memory leak return memory_get_usage(); } ... //somewhere: while(1) { $result = $trollservice->trolling(); }
the $result n iteration > n-1 iteration. how possible? not $trolls variable local variable, should automatically delete after return function? o.o
so, how can clear memory before next iteration?
doctrine keeps in memory fetched objects: method avoid db interrogation.
this mechanism known identity map
this called “identity map” pattern, means doctrine keeps map of each entity , ids have been retrieved per php request , keeps returning same instances.
remember default logging of sql connection set value of
kernel.debug
, if have idebug set true every sql command stored in memory each iteration.
(from doctrine2 documentation)
if want clear memory have use $this->entitymanager->clear();
last instruction of trolling()
function
public function trolling() { $repository = $this->entitymanager->getrepository('trollbundle:troll'); $trolls = $repository->findall(); //memory leak $this->entitymanager->clear(); //here return memory_get_usage(); }
Comments
Post a Comment