Answer the question
In order to leave comments, you need to log in
PHP. Why does the peak value of used memory increase when clearing variables and arrays?
I've been doing performance optimizations in my PHP scripts.
I see that in the course of script execution there is a lot of unnecessary data in memory.
There was an idea to clear the data received from a DB when they were used, by means of unset.
The sooner I erase, the faster they will not take up memory - the logic is this.
For example:
$a=mysql_query("SELECT etc");
while($b=mysql_fetch_assoc($a)){
//do some
}
unset($a);
$log->LogDebug('MemUsage (after all) '.(memory_get_usage()-$base_memory_usage).'. Memory peak was '.memory_get_peak_usage(TRUE).'.');
MemUsage (after all) 281080. Memory peak was 559024.
MemUsage (after all) 275008. Memory peak was 576728.
MemUsage (after all) 274608. Memory peak was 579024.
MemUsage (after all) 274272. Memory peak was 786432.
Answer the question
In order to leave comments, you need to log in
It is not very clear why when deleting arrays and variables, the peak memory usage of the script grows.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question