I'm developing a C/C++ server application using docker and kubectl.
When I watch the server memory usage using 'docker stats' or 'kubectl top pod',
I found the 'MEM USAGE in docker' and 'MEMORY(bytes) in kubectl' does not check deleting heap memory.
In valgrind, it's not a memory leaks.
For example)
- is ok in 'docker stats' or 'kubectl top pod'.
int buf[100000];
- is ok in 'docker stats' or 'kubectl top pod'.
int* buf = new int[100000];
delete[] buf;
- it catch memory not decress in 'docker stats' or 'kubectl top pod'
int* buf = new int[100000]();
delete[] buf;
In 1) is in the stack memory, so there are no leaks.
In 2) the array was declared, but a memory leak did not occur because it was in state "Memory Reserved".
In 3) memory leak of 100000 * 4 bytes occurred because it was in state "Memory Reserved and Committed" by new int[100000]()
Deleting the heap memory does not seem to be reflected in the "docker stats" and "kubectl top pod" indicators.
If this problem persists, the server application will be killed by OOM killer event.
Should I change all dynamic allocation declarations to use stack memory?
or Does any method to avoid this situation? Please advise me.
Thanks.