# Specific 3D Printers, Scanners, & Hardware > RepRap Format Printer Forum > Firmware Enhancements to Marlin >  M99 Free Memory Watcher function for debug

## Roxy

Attached is the M99 Free Memory Watcher function.  It is primarily for developers, but if you are doing something where you are worried that you are running out of memory, this will help confirm or dismiss that concern.

Put the attached file in your Marlin code directory.  And then make these three changes to your code base:

In Marlin_Main.cpp you need to add a declaration up at the top somewhere saying:



```
#ifdef M99_FREE_MEMORY_WATCHER
void m99_code();
#endif
```

and then I put the actual call to it just above the M48 case: statement:



```
#ifdef M99_FREE_MEMORY_WATCHER
case 99: m99_code();
break;
#endif
// M48 Z-Probe repeatability measurement function
```

And then in Configuration.h you need 1 line to control the option:



```
//
// M99 Free Memory Watcher
//
#define M99_FREE_MEMORY_WATCHER // uncomment to add the M99 Free Memory Watcher for debug purpose
```

There are instructions for its use at the top of the M99_Free_Mem_Chk.cpp file.  They are repeated here:



```
// M99 Free Memory Watcher     
//
// This code watches the free memory block between the bottom of the heap and the top of the stack.
// This memory block is initialized and watched via the M99 command.
//
// M99 I   Initializes the free memory block and prints vitals statistics about the area
// M99 F   Identifies how much of the free memory block remains free and unused.  It also
//         detects and reports any corruption within the free memory block that may have
//         happened due to errant firmware.
// M99 D   Does a hex display of the free memory block along with a flag for any errant
//         data that does not match the expected value. 
// M99 C x Corrupts x locations within the free memory block.   This is useful to check the
//         correctness of the M99 F and M99 D commands.
```

----------

