class ABC
{
public $numBox = array();
public function ddd(){
for($i=1; $i<=600; $i++){
$this->numBox[] = mt_rand(1,1000000);
}
echo 'Now memory_get_usage: '.memory_get_usage().'<br />';
}
}//End Class
//方案一
$instance = new ABC(); //实例化一次
for($i =0; $i< 50 ; $i++){
$instance->ddd();
}
/*************************************************/
//方案二
for($i =0; $i< 50 ; $i++){
$instance = new ABC(); //循环实例化
$instance->ddd();
}
我用PHP在线运行看了下结果,为什么循环实例化反而更省内存?
慕娘9325324
泛舟湖上清波郎朗
墨色风雨