I've got a command line script that is running an array()
of files through a loop, and using the file name as an argument to call a method on a helper object.
Each run through the script, PHP's memory_get_usage
reports a larger and larger number
53294264
57019624
61374624
65699176
70230600
75157152
79900392
84630472
89359264
94300016
100031176
105202448
110360808
115777528
121146976
126784824
132366952
until I error out with a
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
It's clear that something is leaking memory, or some sort of global/static storage area keeps being added to. What's the best way to debug this kind of error in PHP? Are there common situations where this occurs inadvertently in PHP? Does xDebug have some magic options that can help me pinpoint this? Other tools?
The best I've come up with is following the chain of execution and littering the codebase with calls to memory_get_usage() until I pinpoint the exact problem, but that seems like a tedious and inefficient approach.