Arduino is freaking out with +19,000 bytes sketches

UnaClocker:
Is there a way to make the sketch output the current SRAM usage to the serial port for debugging?

I use the following. I have no idea if it works correctly when the heap is activated (malloc and its ilk). Ideally, the value from the "maximum stack depth" should be used to determine if there is an SRAM overrun (heap and stack overlap).

extern unsigned int __bss_end;
extern void *__brkval;

int freeMemory() 
{
  int free_memory;

  if((int)__brkval == 0)
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  else
    free_memory = ((int)&free_memory) - ((int)__brkval);

  return free_memory;
}