Search code examples
phpmemory-leakssymfony1doctrine

Memory leak in PHP with Symfony + Doctrine


I'm using PHP with the Symfony framework (with Doctrine as my ORM) to build a spider that crawls some sites.

My problem is that the following code generates a memory leak:

$q = $this -> createQuery('Product p');

if($store) {
    $q
        -> andWhere('p.store_id = ?', $store -> getId())
        -> limit(1);
}

$q -> andWhere('p.name = ?', $name);

$data = $q -> execute();
$q -> free(true);
$data -> free(true);
return NULL;

This code is placed in a subclass of Doctrine_Table. If I comment out the execute part (and of course the $data -> free(true)) the leak stops. This has led me to the conclusion that it's the Doctrine_Collection that's causing the leak.


Solution

  • I solved my problems with Doctrine memory leaks by freeing and unseting data, did you try it?

    // ...
    $data->free(true) ;
    unset($data) ;
    // ...