The failsafe thing to do here is debug your actual memory usage. My recommendation is to rebuild your program from scratch, slowly adding one piece at a time, and testing each one. Check the memory at each stage. This way you can see objectively what's eating up your memory. Also you can call it at various stages in your call stack to see if excessive nesting depth is causing the problem, although that's pretty rare in my experience. Usually the problem is strings or libraries.
This has the added benefit in that code ALWAYS seems to get better after a re-write from scratch, because little problems will become more obvious as we tackle one little piece at a time.
Here is the function I use to check memory. There is one subtlety... If the 'free' memory reports some ridiculously large number, that's actually negative and it means you're out of memory. Also if the Heap is 0 or ridiculously large, that's a problem too.
void* HP = malloc(4);
unsigned long free = (unsigned long)SP - (unsigned long)HP;