These days, I'm trying to determine whether my C++ method (still) has a memory leak. To this end, I wrote a special main
that runs the actual method infinitely over and over and record the memory footprint of the process every minute. One run of the method takes less than a second. The method itself is a little complicated, it internally does some pre-processing, invokes an ONNX model and then does some post-processing on the output. The method is written in a way that one call to it shouldn't increase the memory persistently (i.e., it should free all its local data after exit) and for except one instance, I didn't made use of C-style pointers. valgrind
reports some memory issues in onnxruntime
space, but no memory issues in my code.
If I remove the ONNX part, the RSS memory only ever decreases (x-axis: minutes after start, y-axis: RSS in bytes):
Whereas with the ONNX part, the memory increases slowly over days, until it suddenly sharply falls off:
What are the reasons for this kind of memory behavior? It seems that suddenly, relatively big chunks of memory are freed. Shouldn't memory be freed immediately after a block is exited, so shouldn't the graph be more smooth over time?