I recently made a thread about this issue, assuming that it was caused by a memory leak relating to string usage, however after much testing and learning I've found that the problem is instead much more plain: function calls.
I have a fairly large program that uses a lot of void functions, calling between each other constantly, most of the time not returning anything - at first I thought this was fine, but now I've learned that every time a function is called, it allocates memory in the stack that is not freed up until the call is returned. The problem is, on void functions, there's nothing to return and that would make the flow of the program an impossibility. The problem is that every time a function is called without being returned (Only a few of the functions in the program need to return) it uses up a few bytes of RAM. Sadly, this adds up really quick and after a enough function calls are made the Arduino runs out of memory and proceeds to bug out in a variety of annoying ways.
So my question is: Is there any way to free up the stack space from all the function calls that never get returned? Restructuring the program at this point is pretty much out of the question, it's too complex and intertwined and I'm not sure if the program could be fundamentally restructured without separation into functions as it is now. Or is there any way to 'trick' Arduino into dumping the memory without actually doing a return?
Why do voids work like this? You would expect a function that doesn't return anything to work fundamentally under that assumption - namely that it shouldn't hold RAM space that it will never use forever.
Hope someone can help, thanks in advance.