Most likely, exactly where the problem arose - your script absorbs almost all the limitations of 128 megabytes, and then the database class tries to allocate a little more space for reading something from the database, and the script barfs crosses the limit.
What are you doing, why do you need to use 128 megapixel memory?