使用Symfony + Doctrine在PHP中发生内存泄漏

Nic*_*man 1 php memory-leaks doctrine symfony1

我正在使用PHP与Symfony框架(使用Doctrine作为我的ORM)来构建一个爬行某些网站的蜘蛛.

我的问题是以下代码生成内存泄漏:

$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;
Run Code Online (Sandbox Code Playgroud)

此代码放在的子类中Doctrine_Table.如果我注释掉执行部分(当然还有$data -> free(true)),泄漏就会停止.这使我得出结论,这Doctrine_Collection是导致泄漏的原因.

小智 5

我通过释放取消数据解决了Doctrine内存泄漏的问题,你试过吗?

// ...
$data->free(true) ;
unset($data) ;
// ...
Run Code Online (Sandbox Code Playgroud)