If you really are concerned, write a script and use vmstat(see the man page, but *Always* ignore the first line of output from vmstat) to watch the memory use of the program and have it issue some "flush" command to your program if it reaches a certain threshold. That way you can enjoy not having to make the program have to worry about it, but also not need to worry about missing the event if it happens.
"A man's maturity -- consists in having found again the
seriousness one had as a child, at play." --Nietzsche