0

In a sketch I have, I use a few libraries and have discovered that a large amount of RAM is being consumed.

Is there a tool that can identify how this RAM is being allocated, e.g. which libraries, which piece of code?

  • objdump (packaged with the compiler) can show you static allocations but dynamic allocations require running the code with extra instrumentation added to it or in an instrumented simulator, and even then is confined to the branches explored by the run. – Chris Stratton May 20 '16 at 20:07
  • How have you discovered this? How much RAM? One trick is to use the F() macro around strings that you are printing. Since you didn't post any code, it is hard to give better advice. – Nick Gammon May 20 '16 at 23:06
2

I use this code for Heap memory of AVR (UNO, Mega, etc.):

int freeRam()
{
     extern int __heap_start, *__brkval;
     int v;
     return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
}

To show heap memory just use Serial.print("Write here a name of the function from which you print it"); Serial.println(freeRam()); anywhere in the code.

Compiler shows stack memory but not the heap, so this code helps me to find exact place where my program uses too much of heap memory. I just print it in every suspicious place in my code.

I hope this will help.

Not the answer you're looking for? Browse other questions tagged or ask your own question.