Doctrine 2 で提案されている手法を使用して、多数のオブジェクトを処理しようとしています。この手法は、反復子を使用し、各反復を処理した後にデタッチすることにより、メモリ使用量を最小限に抑える必要があることを示唆しています (10000 レコードを処理するために数 KB の増加について話しています)。
ただし、これを実行しようとすると、解放されたオブジェクトが表示されません。実際、2000 を少し超えるアセットを取得しているため、メモリ使用量が 90 MB 増加しています。明らかに、これらのオブジェクトは解放されません。誰が私が間違っているのか教えてもらえますか? 私のコードは次のようになります。
$profiles = //array of Profile entities
$qb = $this->createQueryBuilder('a')
->addSelect('file')
->leftJoin($profileNodeEntityName, 'pn', JOIN::WITH, 'pn.icon = a OR pn.asset = a')
->leftJoin(
$profileEntityName,
'p',
JOIN::WITH,
'pn.profile = p OR p.logo = a OR p.background = a OR p.pricelistAsset = a OR p.pdfTplBlancAsset = a OR p.pdfTplFrontAsset = a OR p.pdfTplBackAsset = a'
)
->innerJoin('a.currentFile', 'file')
->where('p IN (:profiles)')
->setParameter('profiles', $profiles)
->distinct(true);
$iterableResult = $qb->getQuery()->iterate();
$start = memory_get_usage() / 1024;
while (($row = $iterableResult->next()) !== false) {
// process $row[0]
$this->getEntityManager()->detach($row[0]);
}
$end = memory_get_usage() / 1024 - $start;
// $end is more of less equal to 90000 or 90 MB
ありがとう!