user20793: 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?

user40986: 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.

20793: <p>In a sketch I have, I use a few libraries and have discovered that a large amount of RAM is being consumed. </p>

<p>Is there a tool that can identify how this RAM is being allocated, e.g. which libraries, which piece of code?</p>
 40986: <p>I use this code for Heap memory of AVR (UNO, Mega, etc.):</p>

<pre><code>int freeRam()
{
     extern int __heap_start, *__brkval;
     int v;
     return (int)&amp;v - (__brkval == 0 ? (int)&amp;__heap_start : (int)__brkval);
}
</code></pre>

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

<p>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.</p>

<p>I hope this will help.</p>
