如何查找php脚本的内存消耗?

I am running a php script as a process on a Linux shell. With different tools (top, xdebug, ...) I see the dynamic memory consumption (heap memory) of this very complex script continuously rising.

How can I find out exactly the line in the code or the variable or the place, that is causing this behavior? Where is the memory leak of the php script?

Additional information:

  • Linux version 2.6.30-gentoo-r4
  • PHP Version 5.2.10-pl0-gentoo
  • I can modify the script
  • I can use xdebug

Please give a reason for closing this question.

Try this at suspect areas

echo memory_get_usage();

// Suspect code here

echo memory_get_usage();