i have a script that does a lot of processing on some rows from the DB(lots of them). The script is using lots of objects, and some internal caching mechanisms.
At some point, i’m freeing all used cache, to avoid eating all the available RAM just for the cached items, but the used memory isn’t decreasing.
I’ve used memory_get_usage(true) to determine how much RAM the script is taking, but i have no ideea how to detect what objects are still in RAM and still eating up memory.
The simple solution is to go back through all objects, and make sure no variables are still alive and pointing at them, and that all internal caches are actually free’d and test and test and test again, but I’m looking for a tool or a function call that would tell me that “variable Y in class Z has 90% of your RAM”, without having to know and mess with all the internals of the objects that i use in this script.
Why don’t you profile your script?
Use xdebug with the profiler turned on and investigate what is going on at your cachegrind file.
See more here: http://www.xdebug.org/docs/profiler
Update: You could get more memory related information by using xdebug.show_mem_delta parameter in conjunction with xdebug.trace_format both set to 1 to get memory usage in a simple html.
Check this http://xdebug.org/docs/execution_trace and this http://derickrethans.nl/xdebug-and-tracing-memory-usage.html to get some ideas.