Usually this means the heap size needs to be increased. From my experience, it usually happens during string concatenation or manipulation or printing.
It is an easy fix: set the const HEAPSIZE to a larger value. Try this:
EDIT: In earlier versions it was sometimes necessary to force garbage collection using __gc_collect(), but the current version GC works really well, and just giving the heap more space with HEAPSIZE (and letting it manage GC on its own) is a better fix.
You are using a current version, right? Version 5.0.8 or later?