I’m trying to free up RAM by removing a variable after it is used with the free() function, yet my RAM is not cleaning up. I suppose there is no garbage cleanup taking place? The space cleans up after I exit the section of code (scoped if-statement, while-loop or function), but not the free() statement itself.
I’m doing the following to check the RAM:
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
Additionally, how would one ‘free’ up such memory?
You can’t expect the
__brkvalto decrease just because you calledfree()on a single memory block. The memory block will be marked as free and available for reuse, but in general the__brkvalwill only move in one direction according to the maximum amount of memory that your program uses at any one time.