Clear the heap?

vulture2600:
Is there any kind of command that will clear the heap to prevent stack overflow? If not, does anyone have any clever code that would work in a similar way?

There are two possible things going on here.

#1 - OP has written a bad recursive function.

#2 - OP is using malloc and his kung-fu is not sufficient for the job.

Oh, just thought of a third:

#3 - OP is using the String class.

Actually, #3 is likely to be the culprit. OP: don't use C++ Strings in embedded systems.