You need to play with the garbage collector settings. The ggc-min-expand and ggc-min-heapsize . Also set ulimit to ulimit 65536 (or something else) to reduce the heap size (RLIMIT_AS).
Lots of info on this in the gcc manual here
A good setting would be to set the ggc-min-expand parameter to 0 and ggc-min-heapsize param for 8192 and try with this ...
CXXFLAGS = "$ (CXXFLAGS) --param ggc-min-expand = 0 --param ggc-min-heapsize = 8192" or some such value.
source share