本文介绍了清除 PHP 正在使用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个有趣的问题.我正在使用 PHPUnit,我的测试每次运行时都会占用更多内存.即...

2.25 MB

2.5 MB

3.0 MB

3.5 MB.......

有谁知道如何清除正在消耗的内存,有人可以建议我深入探索这个吗?直接的问题是我的一些较大的测试内存不足,仅仅继续增加 PHP 中的最大内存分配还不够好......我需要知道为什么从命令行运行的 PHPUnit 测试会有内存在运行之间停留"的用法.

解决方案

Calvin,根据 chat 中的讨论,这是由于缺少重置功能.

在测试时,我们必须确保测试环境是一致的,这样我们才能得到准确的结果.计算是输入/输出,因此我们应该使用 Fixtures in PHPUnit 来重置存储以防止内存泄漏";像这些.

I'm running into an interesting problem. I'm using PHPUnit, and my tests take more memory every single time I run them. Ie...

2.25 MB

2.5 MB

3.0 MB

3.5 MB.......

Does anyone know how to clear out the memory that is being consumed, and can anyone advise me on exploring this in depth? The immediate problem is that some of my larger tests are running out of memory, and simply continuing to increase the max memory allotment in PHP isn't good enough...I need to know why a PHPUnit test running from command line would have memory usage which "sticks around" between runs.

解决方案

Calvin, as per discussed in the chat, it was due to missing reset features.

When testing, we must ensure that the test environment is consistent so that we're able to get accurate results. Computing is Input/Output and hence we should use Fixtures in PHPUnit to reset storage to prevent "memory leaks" like these.

这篇关于清除 PHP 正在使用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:09