When I upload my program to Arduino it says the memory that the program is used. But what if I use a bad management of dynamic memory, or any object is created several times in use a lot of memory and the Arduino memory overload.

How do I know the current size of memory that Arduino is use?

I am thinking about to create a function in Arduino that return me this information if I send it a request command, but also I don't know how do I inspect the Arduino memory.

Note: I am using the Board: Arduino Mega 2560.

I read the question and the answer for Measure SRAN usage

In the question @fuenfundachtzig ask:

Can I determine how much SRAM I have left in the live system?

In my question I am asking about how do I know or monitoring my program memmory. Ok the Measure SRAN usage answer give me the tips or tools to develop my idea, but the question is not the same.

I am tryin to know in an specific time what is the size of my memmory.


void setup() { //doing some configuration };

void loop() {  // invoke some functions and evil function  };

// in other place a evil function 

void evil(){
MyClass * instance = new MyClass();
//play with the instance and it class create other instances....
//and a dynamic memmory is used but not deleted.

I am trying to know if it happens and how do I detect with Arduino? I am not talking about how much memmory do I left in the live system.

  • memory used = total memory − free memory. Jun 3, 2015 at 16:14
  • You should not just say your question is different, you should explain how it is different. Be specific about what you are asking for. At this point, it still looks like a duplicate. Jun 3, 2015 at 18:10

1 Answer 1


Basically it looks like you want to figure out if you have a memory leak. Since the objects get allocated continuously you will end up having less and less free memory.

You can use the functions presented in the sister question answered very nicely by Edgar (more specifically the complex one that calculates all the memory going through the allocation chain).

You can check the returned value every so often (few seconds/minutes depending on your needs) and if the free memory value drops continuously then you have a memory leak somewhere. This will not tell you where the leak is of course. Also this should work well while debugging the code, but would probably not be a good idea to leave it in "production" code.

  • I will try with the function that Edgar post, thank you for the answer and comments.
    – Robert
    Jun 4, 2015 at 14:48

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