1, generally speaking, PHP does not need to do memory analysis, but when encountering cycle memory is tight when you have to do memory analysis, see where to eat the memory.
$m 1 = memory_get_usage();
$m 2 = memory_get_usage();
.
.
.
$mn = memory_get_usage();
By subtracting up or down, you know the memory consumption situation.
Reference: http://www.laruence.com/2011/03/04/1894.html
Http://www.cnblogs.com/zcy_soft/archive/2011/04/12/2013223.html
2, when the method is called, it will allocate memory for its local variables, so to see if memory leaks, you should call the method before and after using memory_get_usage(), see the memory changes, if the method has a return value, Also consider the memory that the variable occupies;
When the memory is still large when the method is called, it depends on whether the memory is leaking or whether the data is cached
3, through the layer using memory_get_usage() analysis, find the memory consumption between the layers of similar places, and then quickly locate the memory leak method or function
2 and 3 points are experience
PHP Memory Analysis