我尝试在 MongoDB 中浏览 15 000 个文档。php 使用内存随着 Doctrine ODM 爆炸式增长。我制作了一个顺序脚本,但内存仍在增长。
$nbrNoticesTotal = $noticesNbr['count'];
$page = 0;
$limit = 500;
$pt = 0;
$ptTotal = 0;
$notices = $dm->getRepository('Notice')->findLimit($page, $limit)->toArray();
if ($nbrNoticesTotal > 0) {
while ($ptTotal < $nbrNoticesTotal) {
if ($pt >= $limit) {
unset($notices);
$this->getContainer()->get('doctrine.odm.mongodb.document_manager');
$page += $limit;
$notices = $dm->getRepository('Notice')->findLimit($page, $limit)->toArray();
$pt = 0;
}
foreach ($notices as $key => $notice) {
$pt++;
$ptTotal++;
//unset($notice);
unset($notices[$key]);
}
}
}
memory_get_usage() 的示例:
2012-06-28 14:53:08.541-defaultLogger-DEBUG Start : 20,339,624
2012-06-28 14:53:10.154-defaultLogger-DEBUG get package : 1 - 64,207,344
2012-06-28 14:53:10.891-defaultLogger-DEBUG pointer time : 64,250,536
2012-06-28 14:53:11.642-defaultLogger-DEBUG pointer time : 64,246,952
2012-06-28 14:53:12.375-defaultLogger-DEBUG pointer time : 64,243,368
2012-06-28 14:53:13.140-defaultLogger-DEBUG pointer time : 64,239,784
2012-06-28 14:53:13.911-defaultLogger-DEBUG pointer time : 64,236,264
2012-06-28 14:53:15.359-defaultLogger-DEBUG get package : 2 - 104,447,576
2012-06-28 14:53:17.259-defaultLogger-DEBUG pointer time : 104,482,168
2012-06-28 14:53:19.013-defaultLogger-DEBUG pointer time : 104,478,584
2012-06-28 14:53:20.771-defaultLogger-DEBUG pointer time : 104,475,000
2012-06-28 14:53:22.650-defaultLogger-DEBUG pointer time : 104,471,416
2012-06-28 14:53:24.575-defaultLogger-DEBUG pointer time : 104,467,840
2012-06-28 14:53:26.081-defaultLogger-DEBUG get package : 3 - 139,016,152
2012-06-28 14:53:29.192-defaultLogger-DEBUG pointer time : 139,046,936
2012-06-28 14:53:32.560-defaultLogger-DEBUG pointer time : 139,043,360
2012-06-28 14:53:35.456-defaultLogger-DEBUG pointer time : 139,039,912
2012-06-28 14:53:38.229-defaultLogger-DEBUG pointer time : 139,036,336
我该怎么做才能清除内存?(未设置不起作用)