Reputation: 9291
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?
Upvotes: 4
Views: 2728
Reputation: 993095
You can't expect the __brkval
to decrease just because you called free()
on a single memory block. The memory block will be marked as free and available for reuse, but in general the __brkval
will only move in one direction according to the maximum amount of memory that your program uses at any one time.
Upvotes: 7