Diagnosing Memory Leaks – Allowed memory size of # bytes exhausted

PHP doesn’t have a garbage collector. It uses reference counting to manage memory. Thus, the most common source of memory leaks are cyclic references and global variables. If you use a framework, you’ll have a lot of code to trawl through to find it, I’m afraid. The simplest instrument is to selectively place calls to memory_get_usage and narrow it down to where the code leaks. You can also use xdebug to create a trace of the code. Run the code with execution traces and show_mem_delta.

Leave a Comment