1

For example. At the beginning of the script I created array which has size of 100M. After several operations I unset this array (refcount=0). So, I marked 100M of memory as free, but its still reserved by PHP.

1) Can other scripts which currently run use this memory?

2) At what moment this memory will be free by GC?

  • 1
    You need to rewrite the variable's data in order the immediately free memory. PHP's Garbage Collector doesn't immediately free memory when a variables has zero refcounts. Also the memory limit is per process and as we know apache creates for every request a new process. You should be more worried about the server's ram than about the memory limit. – Charlotte Dunois Aug 10 '15 at 00:07
  • you may want to read this previous answer: http://stackoverflow.com/questions/13667137/the-difference-between-unset-and-null – frymaster Aug 10 '15 at 00:16
  • 1
    @CharlotteDunois Memory will be freed immediately if a variable has zero refcount. However the ZMM allocator may still retain system-level allocations for various reasons, which include a) a small allocation cache and b) cases where other parts of the page on which the allocation happened are still used. It would surprise me though if destroying a 100M array didn't deallocate any memory at system-level. – NikiC Aug 25 '15 at 15:53

0 Answers0