I am testing my C code and detecting memory leak. This piece of code has two functions:
- one of which is to initialize a struct context and allocate momory.
- the other is to finalize this struct context and release memory
I make a loop over these 2 functions like below:
struct context = NULL;
while (1) {
initialize(&context);
sleep(30);
finalize(&context);
sleep(30);
}
And then, I use the htop to monitor the memory leak and get the results below:
VIRT RES -> VIRT RES
745M 78588 -> 126M 24752
672M 79112 -> 281M 51072
671M 81224 -> 281M 55300
671M 81224 -> 281M 55300
671M 81252 -> 281M 55332
671M 96488 -> 281M 70560
671M 102M -> 281M 79368
671M 102M -> 281M 79376
671M 109M -> 281M 85724
671M 111M -> 281M 88152
- The table consists of 10 lines. every line is the change of memory in one loop.
- The left part is the memory state when I initialized the context, and the right part is the memory state when I finalized and released the context.
- I recorded VIRT and RES column number in every state.
- As shown above,
VIRTthe program occupied is a fixed number:671M(when initialized) and281M(when released). But theRESis gradually increasing by every loop.
My question is: Is this called memory leak?