清除 PHP 正在使用的内存
我遇到了一个有趣的问题.我正在使用 PHPUnit,我的测试每次运行时都会占用更多内存.即...
2.25 MB
2.5 MB
3.0 MB
3.5 MB.......
有谁知道如何清除正在消耗的内存,有人可以建议我深入探索这个吗?直接的问题是我的一些较大的测试内存不足,仅仅继续增加 PHP 中的最大内存分配还不够好......我需要知道为什么从命令行运行的 PHPUnit 测试会有内存在运行之间停留"的用法.
解决方案Calvin,根据 chat 中的讨论,这是由于缺少重置功能.</p>
在测试时,我们必须确保测试环境是一致的,这样我们才能得到准确的结果.计算是输入/输出,因此我们应该使用 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.
相关文章