I tested whether unset () affects memory while the script is running, to see if unset () or another known method, $ var = null is more efficient. unset () really affected the memory, but since I tested it on two different virtual hosts, I wondered why it takes twice as much memory for the same script? I suppose the answer is simple, but now it is slipping away from me. The script itself is below:
<?php $init=memory_get_usage(); $test=array(); for($i=0;$i<=100000;$i++){ $test[$i]=rand(0,10000000); } echo 'MEMORY CHANGE: '.((memory_get_usage()-$init)/1024/1024).'MB<br/>'; for($i=0;$i<=100000;$i++){ unset($test[$i]); } echo 'MEMORY CHANGE: '.((memory_get_usage()-$init)/1024/1024).'MB<br/>';
Thanks!
source share