I\'m having trouble in locating the cause for a memory leak in my script. I have a simple repository method which increments a \'count\' column in my entity by X amount:
You're wasting memory for each iteration. A much better way would be to prepare the query once and swap arguments many times. For example:
class MyEntity extends EntityRepository{
private $updateQuery = NULL;
public function incrementCount($id, $ammount)
{
if ( $this->updateQuery == NULL ){
$this->updateQuery = $this->createQueryBuilder('e')
->update('MyEntity', 'e')
->set('e.count', 'e.count + :amount')
->where('e.id = :id')
->getQuery();
}
$this->updateQuery->setParameter('id', $id)
->setParameter('amount', $amount);
->execute();
}
}
As you mentioned, you can employ batch processing here, but try this out first and see how well (if at all) performs...