free ram or read ram ?

can anyone explain how this code is working ? this function recently helped from memory corruption problem. Got it from arduino playground Arduino Playground - AvailableMemory

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

Description was that it suppose to show available ram and it does it. But does it free or defragment ram as well ?

Thanks.

it does not free or defragment ram.

Figure out the problem I was reading outside boundaries of array which was causing the problem but adding this function was solving the problem I cant understand why.

Reading outside boundaries does not cause memory corruption.

Adding the function changes the memory layout of the compiled program. And whatever was corrupting your memory is now corrupting another part of your memory.

“Adding the function changes the memory layout of the compiled program. ”

This explains that behaviour. I was writing to a 4th element of the array which was declared as 3 element array and that was causing one of my global variables to change its value.