$m1 = memory_get_usage(); var_dump($m1); $arr = array_fill(0, 100000, 'phpinfo'); unset($arr); $m2 = memory_get_usage(); var_dump($m2); Var_dump ("Memory Consumption:". ($m2-$m1)/1000);
The output is string(21) “memory consumption: 64.688”;
I don’t understand, I have already used unset for large arrays. where did the 64.688K of memory come from and solve it?
< < better understanding who moved my memory in PHP memory management > >
PHP does not simply ask the OS for memory, but it will ask the OS for a large block of memory, and then allocate one of the blocks to applicants, so when there is logic to apply for memory again,
It is no longer necessary to apply for memory to OS, avoiding frequent system calls.
Before we call
efreeWhen releasing the memory, PHP will not return the memory to the OS, but will put the memory into the free memory list maintained by itself. For small blocks of memory,
More likely, put it in the memory cache list (postscript, some versions of PHP, such as PHP5.2.4, 5.2.6, 5.2.8 that I verified.
get_memory_usage(), the size of the available memory blocks in the memory cache list will not be subtracted, causing it to look like,
unsetMemory will not change in the future.