Insufficient memory to run script

Today I met a boundary when creeating a routine that produces a pricelist in AX 4.0 for a webshop. When creating the required xml I was receiving the error:

Error executing code: Insufficient memory to run script.

It turns out that AX4.0 per default has a 4mb buffersize. And as the resulting xml would contain about 16 mb of data I kept getting the exception. I found good help to increase the buffersize in this post from Martin Dráb.