在函数关闭后PHP不会清除内存使用情况

时间:2014-05-29 11:58:14

标签: php memory yii

我的项目是关于postgis,需要非常大量的数据。 现在我面对着记忆疲惫。所以,我试图打印内存使用情况来检查它,发现在该功能结束后内存不清除。这是我如何进行测试。

    for($i = 0; $i < count($polyLine); $i++){
        echo "BEGIN USE:" .memory_get_usage() . " - PEAK: " . memory_get_peak_usage() . "<br/>";
        $orderPolyLine[$i][] = Utils::mergeLinestringsAfterOffset($polyLine[$i], $overlapPaths[$i]->geom);
        echo "AFTER USE:" .memory_get_usage() . " - PEAK: " . memory_get_peak_usage() . "<br/>";
        echo "------------------------- $i -----------------<br/>";
    }

并且在Utils::mergeLinestringsAfterOffset结束

之前有一个回音
echo "IN FUNCTION USE:" .memory_get_usage() . " - PEAK: " . memory_get_peak_usage() . "<br/>";

并且屏幕上的输出正在跟随。

BEGIN USE:122273264 - PEAK: 122685192
IN FUNCTION USE:127493720 - PEAK: 127802344
AFTER USE:127438320 - PEAK: 127802344
------------------------- 0 -----------------
BEGIN USE:127438320 - PEAK: 127802344
IN FUNCTION USE:185303472 - PEAK: 186612304
AFTER USE:185060120 - PEAK: 186612304
------------------------- 1 -----------------
BEGIN USE:185060120 - PEAK: 186612304
IN FUNCTION USE:211663656 - PEAK: 212287472
AFTER USE:211528488 - PEAK: 212287472
------------------------- 2 -----------------
BEGIN USE:211528488 - PEAK: 212287472
IN FUNCTION USE:214108488 - PEAK: 214419800
AFTER USE:214071624 - PEAK: 214419800
------------------------- 3 -----------------
BEGIN USE:214071624 - PEAK: 214419800
IN FUNCTION USE:236060496 - PEAK: 236967592
AFTER USE:235916176 - PEAK: 236967592
------------------------- 4 -----------------
BEGIN USE:235916176 - PEAK: 236967592
IN FUNCTION USE:238352960 - PEAK: 238708584
AFTER USE:238312440 - PEAK: 238708584
------------------------- 5 -----------------
BEGIN USE:238312440 - PEAK: 238708584

( ! ) Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 438611 bytes) in /Applications/MAMP/htdocs/dlt-gis/vendor/yiisoft/yii/framework/YiiBase.php on line 470

使用线后内存应该减少吗?或者我误解了关于PHP的任何内容? 谢谢你的建议。

编辑:

我也在循环结束前取消了变量,但内存仍然耗尽,并且每个循环都没有减少。

    for($i = 0; $i < count($polyLine); $i++){
        echo "BEGIN USE:" .memory_get_usage() . " - PEAK: " . memory_get_peak_usage() . "<br/>";
        $orderPolyLine[$i][] = Utils::mergeLinestringsAfterOffset($polyLine[$i], $overlapPaths[$i]->geom);
        unset($orderPolyLine);
        echo "AFTER USE:" .memory_get_usage() . " - PEAK: " . memory_get_peak_usage() . "<br/>";
        echo "------------------------- $i -----------------<br/>";
    }

0 个答案:

没有答案