Xdebug is a good tool for finding the root cause of memory allocation problems such as the one shown here:
Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)
First install Xdebug by following the Xdebug installation instructions.
Next surround the code you suspect is causing the problem with the following function calls:
xdebug_start_trace('/tmp/mytrace'); ... Bad bad PHP code ... xdebug_stop_trace();