Why wouldn't a compiler just abort if it runs out of memory? A compiler seems to be a short running program -- I wouldn't even bother too much freeing up allocated memory.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19087 scschnei 25 0 412m 333m 5480 R 100 16.6 0:07.62 cc1plus
Your C++ compiler would be unusable for some modern C++ programs. You're judging how you expect a compiler to behave based on how you've used them in the past. C++ with heavy template meta-programming (like what I was compiling there) can take an enormous amount of memory and CPU time to finish.