Why does this simple php script leak memory?

前端 未结 6 778
故里飘歌
故里飘歌 2020-12-28 18:05

In hopes of trying to avoid future memory leaks in php programs (drupal modules, etc.) I\'ve been messing around with simple php scripts that leak memory.

Could a ph

6条回答
  •  悲哀的现实
    2020-12-28 18:51

    memory_get_usage() does not returns the immediate memory usage, but stored memory to run the process. IN the case of a huge array unset($array_a) will not release memory but consume more according to the memory_get_usage() in my system...

    $array_a="(SOME big array)";
    $array_b="";
    //copy array_a to array_b
    for($line=0; $line<100;$line++){
    $array_b[$line]=$array_a[$line];
    }
    
    unset($array_a); //having this shows actually a bigger consume
    print_r($array_b);
    

    echo memory_get_usage();

提交回复
热议问题