PHP fclose 不释放内存


PHP fclose not freeing up memory

我有一个PHP循环,我读取和处理几个文件的内容。

<?php
foreach($files as $file)
{
    $f = fopen($file, 'r');
    $content = fread($f, filesize($file));
    import($content);
    fclose($f);
}
?>

但是,在循环的几次迭代之后,我仍然在fread()行上收到内存耗尽错误 - 我的理解是使用 fclose() 会释放资源的内存,但事实并非如此吗?

我已经

阅读了有关此事的其他一些问题,它们都引用了我已经在做的fclose()。我也倾倒了memory_get_usage()/memory_get_peak_usage(),他们只是继续上升,直到它失败。

我是否误解了fclose()如何处理释放内存?

<?php
foreach($files as $file)
{
    $f = fopen($file, 'r');
    $content = fread($f, filesize($file));
    import($content);
    fclose($f); // this close file
    unset($content); // this free memory allocated to content of file
}
?>