How to release the memory?
When I call the plot function the memory usage goes up a lot and I do not know how to recycle it.
In theory the python objects are ref-counted and should be correctly destroyed once they leave scope. In practice it's entirely possible that there's a bug somewhere that's leaking references, in that case your only remedy would be to debug the issue (and to submit a PR with the fix afterwards). There's no specific function to manually release memory.
I can confirm there is still a massive memory leak (~5 MB per plot; probably the size of the data to plot) if you loop plots, even if you close them.
This is because if Py_Finalize() is not called, data stays in memory even if it is not displayed. The problem is that if you call Py_Finalize() then you cannot call Py_Initialize() again, basically it is only allowed to call Py_Initialize() and Py_Finalize() once in a program.
Found a solution: force call the Python Garbage collector from time to time (or after each plot)
PyRun_SimpleString("import gc; gc.collect()");