为了避免在php程序(drupal模块等)中避免未来的内存泄漏,我一直在搞乱泄漏内存的简单php脚本.
一位php专家可以帮我找一下这个脚本会导致内存使用量持续攀升吗?
尝试自己运行,更改各种参数.结果很有趣.这里是:
<?php
function memstat() {
print "current memory usage: ". memory_get_usage() . "\n";
}
function waste_lots_of_memory($iters) {
$i = 0;
$object = new StdClass;
for (;$i < $iters; $i++) {
$object->{"member_" . $i} = array("blah blah blha" => 12345);
$object->{"membersonly_" . $i} = new StdClass;
$object->{"onlymember"} = array("blah blah blha" => 12345);
}
unset($object);
}
function waste_a_little_less_memory($iters) {
$i = 0;
$object = new StdClass;
for (;$i < $iters; $i++) {
$object->{"member_" . $i} = array("blah blah blha" …
Run Code Online (Sandbox Code Playgroud)